Computer Logic Design Waqar Baig Lecture 02 Copyrights
Computer Logic & Design Waqar Baig Lecture 02 Copyrights: Dr Waseem Ikram
Recap Last lecture discussion • Decimal Number Systems • Caveman Base 5 Number System • Binary Number System • Number System Conversion Today’s lecture discussion • Decimal-Binary Conversion
Binary to Decimal Conversion • Sum-of-Weights – Expression base number & weights – Sum terms – Paper and pencil method • Sum of non-zero terms – Mental Arithmetic, quick method – Sum of weights of non-zero terms
Binary to Decimal Conversion • Sum-of-Weights • 100112 • (1 x 24) + (0 x 23) + (0 x 22) + (1 x 21) + (1 x 20) • Terms 16, 0, 0, 2 and 1 • 19
Binary to Decimal Conversion • • Add weights of non-zero terms Weights increase/decrease by power of 2 100112 = 16 + 2 + 1 = 19 1011. 1012 = 8 + 2 + 1/2 + 1/8 = 11 + 5/8 = 11. 625
Decimal to Binary Conversion • Sum-of-Weights method used in reverse – Highest binary weight less than the decimal number – Subsequent smaller weights that add up to decimal number • Repeated division by 2 – Paper and pencil method – Number repeatedly divided by 2
Decimal to Binary Conversion using Sum-of. Weights number 392 136 8 Weight Result after subtraction 256 392 -256 = 136 128 136 -128 = 8 64 Binary Bit 1 b 8 1 b 7 0 b 6 8 8 32 16 0 0 b 5 b 4 8 0 0 0 8 4 2 1 1 0 0 0 b 3 b 2 b 1 b 0 8 -8 =0
Decimal to Binary Conversion number 392 196 98 Quotient after division 196 98 49 Remainder after division 0 (b 0) 0 (b 1) 0 (b 2) 49 24 24 12 1 0 (b 3) (b 4) 12 6 3 1 0 0 0 1 1 (b 5) (b 6) (b 7) (b 8)
Binary-Decimal fraction conversion • Binary to Decimal Conversion – Sum-of-Weights method – Weights decrease by a factor of 2 – 0. 11012 weights ½, ¼, 1/16 – Sum up to 0. 8125 • Decimal to Binary Conversion – Repeated Multiplication by 2 – example
Decimal-Binary fraction conversion • Decimal to Binary Conversion – Repeated multiplication by 2 Number Mult. By 2 Integer 0. 8125 1. 625 1 (b-1) 0. 625 1. 250 1 (b-2) 0. 250 0. 500 0 (b-3) 0. 500 1. 000 1 (b-4)
Binary Arithmetic • • Binary Addition Binary Subtraction Binary Multiplication Binary Division
Binary Addition • Four Basic rules for binary addition 1 st digit 0 0 1 1 n 2 nd digit Sum 0 0 1 1 0 Carry 0 0 0 1 Addition of multiple binary numbers
Binary Addition Carry 1 10 1 1 st Number 1 0 1 1 0 0 2 nd Number 3 rd Number 1 4 th Number Result 1 1 1
Binary Subtraction • Four Basic rules for binary subtraction 1 st digit 0 0 1 1 2 nd digit Difference 0 0 1 1 0 Borrow 0 1 0 0
Binary Subtraction Borrow 1 st Number 1 1 0 1 1 2 nd Number 1 1 0 Result 1 0 1
Binary Multiplication • Four Basic rules for binary multiplication n 1 st digit 0 0 1 2 nd digit Product 0 0 1 0 0 0 1 1 1 Example of Binary Multiplication
Binary Multiplication 1 st product term 2 nd product term 3 rd product term Product 1101 x 101 1101 0000 1101 1000001 (13) (5) (65)
Multiplication by shifting left • Decimal 29 shifted left by one digit • 290 • Shift left 1 digit is multiply by 10 • Binary 111012 (29) shifted left by one bit • 1110102 (58) • Shift left 1 bit is multiply by 2
Binary Division 10 101 | 1101 011 000 11
Division by shifting right • Decimal 29 shifted right by one digit • 2. 9 • Shift left 1 digit is divide by 10 • Binary 111012 (29) shifted left by one bit • 1110. 12 (14. 5) • Shift left 1 bit is divide by 2
Signed and Unsigned Numbers • Unsigned Binary Numbers • Signed Binary Numbers – Most significant bit represents sign – 0 represents a positive number – 1 represents a negative number
2’s Complement form • 1’s complement form • 2’s complement form Binary number 1’s complement 2’s complement 01101(13) 10010 + 1 10011(-13)
Addition and Subtraction with 2’s Complement 0101 0010 0111 +5 +2 +7 0101 1110 0011 +5 -2 +3 1011 1110 1001 -5 -2 -7 1011 0010 1101 -5 +2 -3
Range of Numbers • • • Maximum Range Number of digits Decimal number example Binary number example Overflow
Range of Binary Numbers Decimal Number 0 1 2 3 4 5 6 7 Sign Magnitude 2 n-1, 2 n-1 -1 0000 0001 0010 0011 0100 0101 0110 0111 2’s Complement 2 n-1, 2 n-1 -1 0000 0001 0010 0011 0100 0101 0110 0111 Unsigned 2 n, 2 n - 1 000 001 010 011 100 101 110 111
Range of Binary Numbers Decimal Number -8 -7 -6 -5 -4 -3 -2 -1 Sign Magnitude 2’s Complement Unsigned 2 n-1 -1, -(2 n-1 -1) 2 n-1, -2 n-1 1000 1111 1001 1110 1010 1101 1011 1100 1011 1101 1010 1110 1001 1111
Summary • Binary to Decimal Conversion – Sum-of-Weights – Sum of non-zero terms • Decimal to Binary Conversion – Sum-of-Weights (in reverse) – Repeated Division by 2
Summary • Binary to Decimal fraction conversion – Sum-of-Weights • Binary to Decimal fraction conversion – Repeated Multiplication by 2
Summary • Binary Addition • Binary Subtraction • Binary Multiplication – Multiplication by shift left operation • Binary Division – Division by shift right operation
Summary • Unsigned Binary • Signed Binary – Sign Bit • 2’s Complement • 1’s Complement • Range of Binary Numbers
Lecture No. 2 Number Systems
- Slides: 31