Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ahmad Almulhem, KFUPM 2009 COE 202: Digital Logic Design Number Systems Part 4 Dr. Ahmad Almulhem Email: ahmadsm AT kfupm Phone: 860-7554 Office: 22-324.

Similar presentations


Presentation on theme: "Ahmad Almulhem, KFUPM 2009 COE 202: Digital Logic Design Number Systems Part 4 Dr. Ahmad Almulhem Email: ahmadsm AT kfupm Phone: 860-7554 Office: 22-324."— Presentation transcript:

1 Ahmad Almulhem, KFUPM 2009 COE 202: Digital Logic Design Number Systems Part 4 Dr. Ahmad Almulhem Email: ahmadsm AT kfupm Phone: 860-7554 Office: 22-324

2 Ahmad Almulhem, KFUPM 2009 Objectives 1.Overflow 2.Shift operations 3.Binary codes

3 Ahmad Almulhem, KFUPM 2009 Overflows Number’s sizes in computers are fixed Overflows can occur when the result of an operation does not fit. Q: When can an overflow occur? Unsigned numbersSigned numbers Subtracting two numbersAdding a positive number to a negative number Adding two numbersAdding two negative numbers or two positive numbers

4 Ahmad Almulhem, KFUPM 2009 Overflow (2’s Complement) Q: Add +5 and +4 in 2’s complement. A: An overflow happened. The correct answer +9 (1001) cannot be represented by 4 bits. Detection: 1.Adding two positive numbers result in a negative number! 2.Carry in sign bit is different from carry out of sign bit Solution: Use one more bit, extend the sign bit 0101 + 5 10 + 0100 + 4 10 0 1001 - 7 10 ?? 0 1 0 0 00101 + 5 10 + 00100 + 4 10 01001 + 9 10 0 0 1 0

5 Ahmad Almulhem, KFUPM 2009 Overflow (2’s Complement) Q: Add -5 and -4 in 2’s complement. A: An overflow happened. The correct answer -9 (10111) cannot be represented by 4 bits. Detection: 1.Adding two negative numbers result in a positive number! 2.Carry in sign bit is different from carry out of sign bit Solution: Use one more bit, extend the sign bit 1011 - 5 10 + 1100 - 4 10 1 0111 + 7 10 ?? 1 0 0 0 11011 - 5 10 + 11100 - 4 10 10111 - 9 10 1 1 0 0

6 Ahmad Almulhem, KFUPM 2009 Range Extensions To extend the representation of a 2’s complement number possibly for storage and use in a larger-sized register If the number is positive, pad 0’s to the left of the integral number (sign bit extension), and 0’s to the right of the fractional number If the number is negative, pad 1’s to the left of the integral number (sign bit extension), and 0’s to the right of the fractional number 0 1 0 0 10 0 0 0 0 1 0 0 1 5-bit register (+9) 1 0 1 1 11 1 1 1 1 0 1 1 1 5-bit register (-9) 9-bit register (-9) – sign bit extended 9-bit register (+9) – sign bit extended

7 Ahmad Almulhem, KFUPM 2009 Arithmetic Shift A binary number can be shifted right or left To shift an unsigned numbers (right or left), pad with 0s. Example: Left Shift 0001 1 10 0010 2 10 0100 4 10 1000 8 10 Q1: What is the effect of left-shifting? Q2: What is the effect of right-shifting?

8 Ahmad Almulhem, KFUPM 2009 Arithmetic Shift To shift a signed number – Left-Shift: pad with 0s – Right-Shift: Extend sign bit Example (2’s complement): Right Shift 1000 - 8 10 1100 - 4 10 1110 - 2 10 1111 - 1 10 In General - left-shifting = multiply by r - right-shifting = divide by r

9 Ahmad Almulhem, KFUPM 2009 Arithmetic Shifts

10 Ahmad Almulhem, KFUPM 2009 Binary Codes Human communicating with computers – Humans understand decimal – Computers understands binary Communication mode is decimal Binary codes are used to translate individual digits of a given number (generally in base 10) to binary format based on given rules Computers 01011 …. Human 1234 ….

11 Ahmad Almulhem, KFUPM 2009 Binary Coded Decimal (BCD) BCD Code uses 4 bits to represent the 10 decimal digits {0 to 9} 6 BCD codes unused The weights of the individual positions of the bits of a BCD code are: 2 3= 8, 2 2 =4, 2 1 =2, 2 0 =1

12 Ahmad Almulhem, KFUPM 2009 BCD Addition

13 Ahmad Almulhem, KFUPM 2009 Gray Code Gray code represents decimal numbers 0 to 15 using 16 4- bit codes Gray codes of two adjacent decimal numbers differ by only one bit Example: (5) 10 = 0111 (6) 10 = 0101 (7) 10 = 0100

14 Ahmad Almulhem, KFUPM 2009 ASCII Code (Alphanumeric) American Standard Code for Information Interchange (ASCII): includes binary definitions for 128 characters that include the English alphabets, special symbols and control characters. ASCII codes have a length of 7 bits Examples: A = (65) 10 = 100 0001 B = (66) 10 = 100 0010 Z = (90) 10 = 101 1010 a = (97) 10 = 110 0001 b = (98) 10 = 110 0010 z = (122) 10 = 111 1010

15 Ahmad Almulhem, KFUPM 2009 Parity Bits

16 Ahmad Almulhem, KFUPM 2009 Codes Summary Bits are bits – Modern digital devices represent everything as collections of bits – A computer is one such digital device You can encode anything with sufficient 1’s and 0’s – Text (ASCII) – Computer programs (C code, assembly code, machine code) – Sound (.wav,.mp3,...) – Pictures (.jpg,.gif,.tiff)

17 Ahmad Almulhem, KFUPM 2009 Numbers have fixed sizes in a computer, therefore overflow can occur in any representation. Detection of overflow by sign or carry-in carry-out of the sign bit. To extend a signed number, extend the sign Shift operations (right, left) Binary codes (BCD, gray code, ASCII) Conclusions


Download ppt "Ahmad Almulhem, KFUPM 2009 COE 202: Digital Logic Design Number Systems Part 4 Dr. Ahmad Almulhem Email: ahmadsm AT kfupm Phone: 860-7554 Office: 22-324."

Similar presentations


Ads by Google