Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4: Digital Systems & Binary Numbers (4)

Similar presentations


Presentation on theme: "Lecture 4: Digital Systems & Binary Numbers (4)"— Presentation transcript:

1 Lecture 4: Digital Systems & Binary Numbers (4)
CPE 201 Digital Design Lecture 4: Digital Systems & Binary Numbers (4)

2 Lecture Outline Signed numbers Encoding techniques

3 Signed Binary Numbers Cannot use the “minus” sign we use on paper
Signed-magnitude MSB keeps the sign: 0 – positive, 1 – negative Hard to use with arithmetic operations The user determines if the number is signed/not (unsigned binary) or +9 (signed binary) 11001 Other examples: = = = = = = -0 Signed complement used for computer arithmetic Signed 1’s complement and signed 2’s complement 25 (unsigned binary) or -9 (signed binary)

4 Signed Complement Negative number is indicated by its complement
Positive numbers start with 0  complement will always start with 1 (negative number) 2’s complement is most common E.g.: represent -9 on eight bits Represent +9: Signed magnitude: Signed 1’s complement: Signed 2’s complement:

5 Signed Binary Numbers Decimal Signed 2’s compl. Signed 1’s compl.
Signed mag. +7 +6 +5 +4 +3 +2 +1 +0 -0 -1 -2 -3 -4 -5 -6 -7 -8 0111 0111 0111 0110 0110 0110 0101 0101 0101 0100 0100 0100 0011 0011 0011 0010 0010 0010 0001 0001 0001 0000 0000 0000 - 1111 1000 1111 1110 1001 1110 1101 1010 1101 1100 1011 1100 1011 1100 1011 1010 1101 1010 1001 1110 1001 1000 1111 1000 - -

6 Addition of Signed Numbers
Signed magnitude Just like regular arithmetic Same signs: add magnitudes Different signs: subtract smaller magnitude from larger, keep the sign of the larger magnitude Requires comparison and subtraction Complex circuit design Better to use signed complement representation = + 68 (-44) = - 20

7 Addition of Signed Numbers
Use 2’s complement: Represent negative numbers in 2’s complement Perform addition as usual MUST USE THE SAME NUMBER OF BITS FOR BOTH NUMBERS AND THE SUM

8 Addition of Signed Numbers
Signed 2’s complement: 3+4, -2+(-6), 6+(-3), 4+(-7) +3 + -2 + + +4 + -6 +7 -8 1 Discard carry +6 + +4 + + -3 + -7 +3 -3 Discard carry

9 Overflow Addition can result in overflow if there isn’t enough space available to represent the result Can occur only if operands have the same sign Overflow occurs when the carry bits into and out of the sign position are different E.g.: + +7 + +7 +14 = -2 !! 1 carry into sign bit carry out of + -3 + -6 -9 1 carry into sign bit carry out of = 7 !!

10 Subtraction with Signed 2’s Complement
Take the 2’s complement of the subtrahend (including the sign bit) Add it to the minuend (including the sign bit) Ignore any carry out of the sign-bit Make sure to check for overflow A – (+B) = A + (-B) A – (-B) = A + (+B) Equivalent to taking the 2’s complement

11 Examples: Subtraction Signed 2’s Complement
4 – 3 = 0100 – 0011 = = 10001 3 – 4 = 0011 – 0100 = = 1111 1111 is equal to -1 in 2’s complement 3 – (-4) = 0011 – (-(0100))in 2’s complement = = 0011 – 1100 = = 0111 = 710 -3 – (-4) = 1101 – 1100 = = 10001 = 110 Discard the carry Instead add 2’s complement Discard the carry

12 Binary Codes Is binary the only way to encode information?
Same information can be coded using a different code The encoding still uses 0’s and 1’s E.g.: represent the decimal values 1-9: Binary: 0001  1001 One out of 9: , , , … , A code is a set of n-bit strings, which assigns a unique string to any symbol

13 Binary Coded Decimal (BCD) Code
In BCD, each decimal digit is represented with its binary encoding Easier for people to understand than binary How many bits do we need to represent numbers 0 through 9 in BCD? 4 bits E.g.: (527)10 = ( )BCD A number with k digits in decimal requires 4k bits in BCD Do not confuse with binary representation! 5 2 7

14 Addition using BCD code
Similar to adding 4-bit unsigned binary numbers A correction must be made if the result exceeds 1001 (9) Addition result range is 0 to 19 (9+9+1carry) Binary: 0000 to 10011 BCD: to The difference in result between the BCD and binary values is 6 (110) If the result is  1010 (10 decimal), adding 6 (110) to the result will correct the problem

15 BCD Addition Example 5 + 9 , 8 + 8, 9 + 9 Results:
5 + 9 = = 1110 (need correction) add 110: = (1410) 8 + 8 = = (need correction)  add 110: = (1610) 9 + 9 = = (need correction)  add 110: = (1810)

16 Readings Chapter 2 Sections 1.7


Download ppt "Lecture 4: Digital Systems & Binary Numbers (4)"

Similar presentations


Ads by Google