ahmad almulhem, kfupm 2009 coe 202: digital logic design number systems part 4 dr. ahmad almulhem...
TRANSCRIPT
![Page 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/1.jpg)
Ahmad Almulhem, KFUPM 2009
COE 202: Digital Logic DesignNumber Systems
Part 4
Dr. Ahmad AlmulhemEmail: ahmadsm AT kfupm
Phone: 860-7554Office: 22-324
![Page 2: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/2.jpg)
Ahmad Almulhem, KFUPM 2009
Objectives
1. Overflow
2. Shift operations
3. Binary codes
![Page 3: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/3.jpg)
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 numbers Signed numbers
Subtracting two numbers Adding a positive number to a negative number
Adding two numbers Adding two negative numbers or two positive numbers
![Page 4: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/4.jpg)
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 + 510
+ 0100 + 410
0 1001 - 710 ??
0 1 0 0
00101 + 510
+ 00100 + 410
01001 + 910
0 0 1 0
![Page 5: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/5.jpg)
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 - 510
+ 1100 - 410
1 0111 + 710 ??
1 0 0 0
11011 - 510
+ 11100 - 410
10111 - 910
1 1 0 0
![Page 6: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/6.jpg)
Ahmad Almulhem, KFUPM 2009
Range ExtensionsTo extend the representation of a 2’s complement number
possibly for storage and use in a larger-sized registerIf 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 numberIf 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 1 0 0 0 0 0 1 0 0 1
5-bit register (+9)
1 0 1 1 1 1 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
![Page 7: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/7.jpg)
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 110
0010 210
0100 410
1000 810
Q1: What is the effect of left-shifting?Q2: What is the effect of right-shifting?
![Page 8: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/8.jpg)
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 - 810
1100 - 410
1110 - 210
1111 - 110
In General- left-shifting = multiply by r- right-shifting = divide by r
![Page 9: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/9.jpg)
Ahmad Almulhem, KFUPM 2009
Arithmetic Shifts
![Page 10: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/10.jpg)
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 ….
![Page 11: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/11.jpg)
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: 23=8, 22=4,
21=2, 20=1
![Page 12: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/12.jpg)
Ahmad Almulhem, KFUPM 2009
BCD Addition
![Page 13: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/13.jpg)
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
![Page 14: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/14.jpg)
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 bitsExamples:
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
![Page 15: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/15.jpg)
Ahmad Almulhem, KFUPM 2009
Parity Bits
![Page 16: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/16.jpg)
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)
![Page 17: 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](https://reader036.vdocuments.site/reader036/viewer/2022082820/5697bf781a28abf838c81f55/html5/thumbnails/17.jpg)
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