Beruflich Dokumente
Kultur Dokumente
Lecture 2-2
Number Systems and Data Representation
Outline
Understand the concept of computer codes.
Recognise the commonly used digital codes such as ASCII, Binary
Coded Decimal (BCD) and Gray code.
Express decimal numbers in BCD form.
Add BCD numbers.
Convert between the binary system and the Gray code.
copyright 2009 Mok KM
Computer Codes
A code is the use of a number system for representing information
Solution 1
9 -> 1001
7 -> 0111
5 -> 0101
0 -> 0000
Solution 2
(a) 0 0 0 1 0 1 1 0
+ 0 0 0 1 0 1 0 1
0 0 1 0 1 0 1 1 Right group is invalid (>9), left group is valid
0 1 1 0 So, add 6 to invalid code for correction.
+ 1 Add carry, 0001 to next group.
0 0 1 1 0 0 0 1 Valid BCD number.
(b) 0 1 0 1 0 1 1 1
+ 0 1 1 0 0 0 1 1
1 0 1 1 1 0 1 0 Both groups are invalid (>9)
0 1 0 1 0 1 1 0 Add 6 to both groups.
+ 1 1 Carries generated due to (>9)
0 0 0 1 0 0 1 0 0 0 0 0 Valid BCD number.
copyright 2009 Mok KM
Gray Code
Gray code is unweighted
Cannot be used for arithmetic operations
Commonly used in data transfer applications
Gray code can be any length
Gray code Binary Decimal
G[3:0] B[3:0] Value
0000 0000 0
Example, a 4- 0001 0001 1
bit Gray code
0011 0010 2
MSB LSB
B[3] B[2] B[1] B[0] Binary
0 + 1 + 1 + 0
0 1 0 1
G[3] G[2] G[1] G[0] Gray
In terms of hardware:
Deduce the Boolean equations from the above.
- G[3] = B[3]
- G[2] = B[2] B[3]
- G[1] = B[1] B[2]
- G[0] = B[0] B[1]
copyright 2009 Mok KM
MSB LSB
G[3] G[2] G[1] G[0] Gray
1 0 1 1
+ + +
1 1 0 1
B[3] B[2] B[1] B[0] Binary
In terms of hardware:
Deduce the Boolean equations from the above.
- B[3] = G[3]
- B[2] = B[3] G[2] = G[3] G[2]
- B[1] = B[2] G[1] = G[3[ G[2] G[1]
- B[0] = B[1] G[0] = G[3] G[2] G[1] G[0]
copyright 2009 Mok KM
ASCII (American Standard Code for Information Interchange)
Example 1:
ASCII code representation of the word "Digital" is shown