You are on page 1of 29

Chapter 1 : Introduction to Binary Systems

By Dr. Ridha Jemal


Electrical Engineering Department College of Engineering King Saud University 1431-1432
1.1. Introduction to digital Systems 1.2. Binary numbers 1.3. Number base conversion 1.4. Octal and Hexadecimal Numbers 1.5. Complements 1.6. Signed Binary Numbers 1.7. Arithmetic Operations in bases 1.8. Logic gates
Dr. Ridha Jemal EE208: Logic Design 1431-1432 Chapter 1 page: 1

Introduction to Digital Systems


The purpose of this chapter is to show you how familiar numeric quantities can be represented and manipulated in a digital system, and how nonnumeric data, events, and conditions also can be represented

Digital systems are built from circuits that process binary digits 0s and 1s and are used in:
o Communication; oTraffic control and Space guidance; o Medical treatment; o Weather monitoring; o Digital telephone, Television and Camera o Digital Computer and Internet

One characteristic of Digital Systems is their ability to manipulate discrete element of information like : o 10 decimal digits from 0..9 ; o 26 letters of the alphabet from a.. Z
Dr. Ridha Jemal EE208: Logic Design 1431-1432 Chapter 1 page: 2

Introduction to Digital Systems


Discrete elements of information are represented in digital system by physical quantities called signals (Electrical Signals like voltage or current) The electronic device called transistor predominates in the circuitry that implements these signals. The signals use just two discrete values and therefore said to be binary
Therefore, a digital system designer must establish some correspondence between the binary digits processed by digital circuits and real-life numbers, events, and conditions. In Electrical Wire: 0 refers to the state No current in the wire 1 refers to the state There is a current in the wire

Discrete elements of information are represented with a group of bits called binary Codes.
For example: Decimal digits 0 to 9 are represented in digital system with code of 4 bits.
EE208: Logic Design 1431-1432 Chapter 1 page: 3

Dr. Ridha Jemal

Introduction to Digital Systems

The Digital System is a system that manipulates discrete elements of


information that is represented internally in binary form. The general purpose of digital compute is the best known example of digital system. The major parts of a computer are: o Central Processor Unit: It performs arithmetic and logic operations and
other data processing. o Memory Unit: It stores programs as well as input, output and intermediate data. o Input/Output Unit: The program and data prepared by a user are transferred into memory by means of an input device such as keyboard. An output device as printer, receives that results of the computation to be printed.

Dr. Ridha Jemal

EE208: Logic Design 1431-1432

Chapter 1 page: 4

Introduction to Digital Systems


CPU IO Memory A digital System is an interaction of digital modules

To understand the operation of each digital module it is necessary to have a basic knowledge of digital circuits and their logic function The digital computer manipulates : oNumerical values; oLogic Values; oSet of symbol oMisc objects: voice, images, etc
Dr. Ridha Jemal EE208: Logic Design 1431-1432 Chapter 1 page: 5

Introduction to Digital Systems


CPU IO Memory A digital System is an interaction of digital modules

To understand the operation of each digital module it is necessary to have a basic knowledge of digital circuits and their logic function The digital computer manipulates : oNumerical values; oLogic Values; oSet of symbol oMisc objects: voice, images, etc
Dr. Ridha Jemal EE208: Logic Design 1431-1432 Chapter 1 page: 6

Binary Numbers
A decimal number 7251 represents a quantity equal to : 7 thousands + 2 hundreds + 5 tens + 1 unit To be more exact this number should be written as: 7 x 103+ 2 x 102 + 5 x 101 + 1 x 100 In general a number with decimal point is represented by a series of coefficients as follows : a4 a3 a2 a1 a0 a-1 a-2 a-3 The aj coefficients are any of the 10 digits (0, 1, 2, , 9), and the subscript value j gives the place value and, hence, the power of 10 by which the coefficient must be multiplied. This can be expressed as: a4x104 + a3x103+ a2x102 + a1x101+ a0x100 + a-1x10-1 + a-2x10-2+ a-3x10-3

The General form can be expressed as: anx10n + an-1x10n-1 + + a0x100 + a-1x10-1 + + a-mx10-m n = (digit number before the point )-1 m = digit number after the point
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 7

Binary Numbers
The decimal number system is said to be of base or radix 10 because it uses 10 digits and the coefficient are multiplied by power of 10. The binary system is a different number system. The coefficients of the binary number have only two possible values : 0 or 1. Each coefficient aj is multiplied by 2j For example, the decimal equivalent of the binary number 11010.11 is .. as shown from the multiplication of the coefficient by powers of 2 1x24 + 1x23 + 0x22 + 1x21 + 0x20 + 1x2-1 + 1x2-2 = 26.75 For example, a number expressed in a base-r system has coefficients multiplied by powers of r an x rn + an-1 x rn-1 + + a2 x r2 + a1 x r1 + a0 x r0 + a-1 x r-1 + + a-m x r-m

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 8

Binary Numbers
There are may bases:

r=2 o Base-5 System: r=5 o Octal System : r=8 o Hexadecimal System : r = 16


o Binary System :

It manipulates 2 digits or bits 0, 1 It manipulates 5 digits : 0, 1, 2, 3, 4 It manipulates 8 digits : 0, 1, 2, 3, 4, 5, 6, 7 It manipulates 16 digits : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Examples:
o o o o (4021.2)5 (127.4)8 (B65F)16 (110101)2 = = = = 511.4 10 87.5 10 46687 10 53 10

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 9

Number Base Conversion


The conversion of a number in base r to decimal is done by expanding the number in a power series and adding the terms as shown previously: In fact, the general form of a number D is : an . a2 a1 a0 a-1 a-2 a-m And its value expressed in the base r is: an x rn + an-1 x rn-1 + + a2 x r2 + a1 x r1 + a0 x r0 + a-1 x r-1 + + a-m x r-m where r is the radix of the number and there are n digits to the left of the radix point and m to the right. For example if r=10, the value of the number can be found by converting each digit of the number to its radix-10 equivalent and expanding the formula using radix-10 arithmetic. Some examples are given below:
1CE816 = 1163 + 12162 + 14161 + 8160 = 740010 F1A316 = 15163 + 1162 + 10161 + 3160 = 6185910 436.58 = 482 + 381 + 6 80 + 581 = 286.62510 132.34 = 142 + 341 + 2 40 + 341 = 30.7510
EE351: Control Systems 1431-1432 Chapter 1 page: 10

Dr. Ridha Jemal

Number Base Conversion

We now present a general procedure for the reverse operation of converting a decimal number to a number of base r
Consider what happens if we divide the formula by r we will get a quotient Q and a reminder di. The quotient has the same form as the original formula .Therefore, successive divisions by r will yield successive digits of D from right to left, until all the digits of D have been derived. The sequence of reminders are listed in the reverse order of the division process

Decimal Integer to Binary Conversion


179 : 2 = 89 remainder 1 (LSB) : 2 = 44 remainder 1 : 2 = 22 remainder 0 : 2 = 11 remainder 0 : 2 = 5 remainder 1 : 2 = 2 remainder 1 : 2 = 1 remainder 0 : 2 = 0 remainder 1 (MSB)
The result can be expressed as : 179 10 = 101100112

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 11

Number Base Conversion


Decimal Fraction to Binary Conversion
Similar method is applied, just the division is replaced by multiplication for the right after the point Example : 0.687510 0.6875x2 = 1 + 0.3750 0.3750X2 = 0 + 0.7500 0.7500x2 = 1 + 0.5000 0.5000x2 = 1 + 0.0000 0.687510 = 0.10112

Decimal Fraction to Octal Conversion


0.51310 0.513x8 = 0.104X8 = 0.832x8 = 0.656x8 = 0.248x8 = 0.984x8 = 0.51310 = 0.4065178 4 0 6 5 1 7 + + + + + + 0.104 0.832 0.656 0.248 0.984 0.872
Chapter 1 page: 12

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Number Base Conversion


The conversion from and to binary, octal and Hexadecimal plays an important role in digital computers. Since 23=8 and 24=16 each octal digit corresponds to three binary digits and each hexadecimal digit correspond to four binary digits.

Binary to Octal/Hexadecimal Conversion


The conversion is easily accomplished by partitioning the binary number into group of three digits for the octal conversion and four digits for the hexadecimal conversion Examples : o (10 110 001 101 011 . 111 100 000 110)2 = (26153.7406)8 o (10 1100 0110 1011 . 1111 0010)2 = (2C6B.F2)16

Octal/Hexadecimal to Binary Conversion


Conversion from octal or hexadecimal to binary is done by reversing the preceding procedure . Each octal digit is converted to its three-digit binary equivalent. Similarly, each hexadecimal digit is converted to its four-digit binary equivalent. Examples : o (673.124)8 = (110 111 011. 001 010 100)2 o (306.D)16 = (0011 0000 0110 . 1101)2
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 13

Number Base Conversion


Decimal (Base 10) 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
Dr. Ridha Jemal

Binary (Base 2) 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Octal (Base 8) 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17

Hexadecimal (Base 16) 0 1 2 3 4 5 6 7 8 9 A B C D E F


Chapter 1 page: 14

EE351: Control Systems 1431-1432

Complements
Complements are used in digital computer for simplifying the subtraction operation and for logical manipulation. There are two types of complements for each base-r system: The radix complement (rs complement) The diminished radix complement ((r-1)s complement)

The (r-1)s complement


Given a number N in base r having n digits, the (r-1)s complement of N is defined as (rn 1) N o For r=10, r-1=9, so the 9s complement of N is (10n -1) N The 9s complement of 546700 is 999999 546700 = 453299 The 9s complement of 012398 is 999999 012398 = 987601
o For r=2, r-1=1, so the 1s complement of N is (2n -1) N o N=4 ; 24= 100002 and 24 1=1111. The 1s complement is obtained by subtracting each digit from 1. We have one of the following cases :1 -0 or 1-1.
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 15

Complements
The 1s complement is obtained by changing 1s to 0s and 0s to 1s The 1s complement of 1011000 is 0100111

The radix complement (rs complement)


The rs complement = the (r-1)s complement + 1 [(rn 1) N]+1
o For r=10,

The 10s complement of 012398 is 987602 The 10s complement of 246700 is 753300
o For r=2,

Given a binary umber 10100101 The 1s complement of 10100101 is 01011010 The 2s complement of 10100101 is 01011010+1 = 01011011
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 16

Signed Binary Numbers


Negative Number
Positive integers can be represented by unsigned numbers. However, to represent negative integers, we need a notation for negative values
The sign is represented by a bit placed in the leftmost position of the number. The convention is to make the sign bit 0 for positive 1 for negative.

0 1010010 as unsigned number is equal to : 1 1010010 as unsigned number is equal to : 1 1010010 as signed number is equal to :
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 17

Signed Binary Numbers


Number line extends in both directions:

Ways to represent numbers less than zero:

Signed Magnitude
Use MSB as a flag: 0=+ve, 1=-ve ("sign bit") All other bits hold the magnitude eg. using 4 bits 0110 = 6 1010 = -2

Ones Complement
Given a number N in base 2 having n digits, the 1s complement of N is defined as (2n 1) N The 1s complement is obtained by changing 1s to 0s and 0s to 1s The 1s complement of 1011011 is 0100100
EE351: Control Systems 1431-1432 Chapter 1 page: 18

Dr. Ridha Jemal

Signed Binary Numbers


Twos Complement
To negate number: Invert all bits and add 1 ; eg. -2 using 8 bits * 0000 0010 inverted is 1111 1101 * Add 1: 1111 1110 (-2) Another way: Start writing down the number from left. Write the number exactly as it appears until the first one. Write down the first one and invert all digits to its left

Examples : Find the 2s complement using 8 bits


1. +8 = 00001000 1000 write number to first one 111 invert the remaining bits -8 = 11111000 +13 = 00001101 1s com.: 11110010 2s com.: 11110011 -13 = 11110011
EE351: Control Systems 1431-1432 Chapter 1 page: 19

1.

Dr. Ridha Jemal

Arithmetic Operations in bases (Add, Sub)


Addition/subtraction
If the signs are the same, we add two magnitudes and gives the common sign

Example 1:
+8 +17 +25 001000 010001 011001 + 24 + 32 +56 0011000 0100000 --------------------------------------0111000

-------------------------------

If the signs are different, we subtract the smaller magnitude from the larger and we give the result the sign of the larger magnitude. This process requires a comparison and subtraction. So we will use only the addition in the signed complement system without need to use the comparison and the subtraction. Subtraction = Addition of the 2s complement of the negative number
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 20

Arithmetic Operations in bases (Add, Sub)


Example 2
+17 -8 010001 101000 010001 111000 2s complement of 001000 ----------------------------------------------------001001

The sign bit is not complemented

+9

If the result is negative, we will take its 2s complement to get the final result

Example 3:

+ 24 0011000 - 35 1100011 -------------------------------

0011000 1011101 2s complement of 0100011 --------------------------------------1110101 Its a negative number, we take its

2s complement which is : 1001011 equal to -11

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 21

Arithmetic Operations in bases (Add, Sub)


Example 4: +35 -72 = ???
+ 35 - 72 00100011 11001000 00100011 10111000 2s complement 0f 01001000 --------------------------------------11011011 Its a negative number,

we take its 2s complement which is : 00100101 equal to - 37

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 22

Binary Code Character Sets


ASCII - American Standard Code for Information Interchange
a.k.a ISO 646-1973 (international) BS 4730: 1974 (British Standard) 7-bit code (128 different characters) Numerals, punctuation and letters American alphabet... ... no symbols for , , etc. Still VERY widely used EBCDIC - Extended Binary-Coded-Decimal Interchange Code Proprietary to IBM 8-bit code Not compatible with ASCII ISO Latin1 - 8-bit code Extension to ASCII (ASCII is compatible) Has characters for European languages Future - include ALL characters from ALL languages (!) Unicode (16 bits) ISO 10646 (32 bits)
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 23

Binary Codes
Digital Systems represent and manipulate not only binary numbers but also many other discrete elements of information which can be represented by a binary code. An n-bit binary code is a group of n bits that assume up to 2n distinct combinations of 1s and 0s. Examples: o A set of four elements can be coded with two bits: 00, 01, 10 and 11 o A set of 16 elements requires a 4-bit code Decimal Symbol BCD Digit BCD Code (Binary Coded Decimal) 0 0000 1 0001 A number with k decimal digits will 2 0010 require 4k bits in BCD 3 0011 4 0100 5 0101 (396)10 = (0011 1001 0110)BCD 6 0110 7 0111 8 1000 9 1001
Dr. Ridha Jemal EE351: Control Systems 1431-1432 Chapter 1 page: 24

Binary Codes
BCD Addition

Consider the addition of two decimal digits in BCD, together with a possible carry from previous less significant pair of bits: If the result is greater or equal 1010, the result is an invalid BCD digit; The addition of 6 = (0110)2 to the binary sum converts it to the correct digit and also produces a carry as required.
Examples: 4 0100 +5 +0101 ----------------+9 1001

4 0100 +8 +1000 ---------------------12 1100 + 0110 ---------------------12 1 0010


EE351: Control Systems 1431-1432 Chapter 1 page: 25

Dr. Ridha Jemal

Binary Codes
BCD Addition (contd.) The addition of two n-digit unsigned BCD numbers follows the same procedure. Consider the addition of 184 +576
184 +576 0001 1000 0100 +0101 0111 0110 -------------------------------0110 1111 1010 0110 0110 1 1 -------------------------------0111 0110 0000 7 6 0

+ +

Dr. Ridha Jemal

EE351: Control Systems 1431-1432

Chapter 1 page: 26

Gray and ASCII Codes


Gray Code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
Dr. Ridha Jemal

Decimal Equivalent 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

ASCII Code 100 0001 110 0001 100 0010 110 0010 . . . 100 0110 110 0110 100 0111 110 0111 . . . 011 0001= 31Hex 011 0011= 33Hex

Characters A a B b . . . F f G g . . . 1 3
Chapter 1 page: 27

EE351: Control Systems 1431-1432

Binary Logic
AND gate
Binary Logic consists on Binary variables and Logical operations o Variables : A, B, C, . Z, a, b, c, 1, 2, 3 expressed in the binary system o Logical Operations : 3 fundamental operations A ND, OR, INV

AND : Result TRUE if and only if both input operands are true C= AB Its graphic Symbol is:
A B
Dr. Ridha Jemal

A 0

B 0

C 0

0
1 C 1

1
0 1

0
0 1

EE351: Control Systems 1431-1432

Chapter 1 page: 28

Binary Logic
OR and NOT gates

OR : Result TRUE if operands are true C= A+B C Its graphic Symbol is: A B

A 0

B 0

C 0

0
1 1

1
0 1

1
1 1

NOT : Result TRUE if single input value is FALSE C= A C Its graphic Symbol is: A
Dr. Ridha Jemal EE351: Control Systems 1431-1432

A
0 1

C
1 0

Chapter 1 page: 29

You might also like