Lecture No.
4
Number Systems
BCD (Binary Coded Decimal) Code
• Binary Code to represent decimal digits 0-9
• Used by Decimal Number Displays
BCD (Binary Coded Decimal) Code
Decimal BCD Decimal BCD
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001
BCD Addition
• How to ADD two BCD numbers:
Step 1: Add the two BCD numbers, using rule of binary Addition
Step 2:If 4-bit sum is equal to or less than 9, it is a valid BCD
Step 3: If a 4-bit sum is greater than 9. or if a carry out is generated, it is an
invalid result. Add 6(0110) to four bit sum in order to skip six invalid states
and return code to 8421. If a carry results when 6 is added, simply add the
carry to the next 4-bit group
BCD Addition
23 0010 0011
45 0100 0101
68 0110 1000
23 0010 0011
49 0100 1001
72 0110 1100
• 1100 is illegal BCD number
BCD Addition
• Add a 0110 (6) to an invalid BCD number
• Carry added to the most significant BCD digit
23 0010 0011
49 0100 1001
72 0110 1100
0110
0111 0010
DECIMAL
CODES
UNUSED COMBINATIONS
Excess Code
• A bias is added to Binary Code
• Used by floating point numbers
Excess-8 Code
Decimal 2’s Excess-8 Decimal 2’s Excess-8
Comp. Comp.
0 0000 1000 -8 1000 0000
1 0001 1001 -7 1001 0001
2 0010 1010 -6 1010 0010
3 0011 1011 -5 1011 0011
4 0100 1100 -4 1100 0100
5 0101 1101 -3 1101 0101
6 0110 1110 -2 1110 0110
7 0111 1111 -1 1111 0111
Gray Code
• Binary Code more than 1 bit change
• Electromechanical applications of digital systems
restrict bit change to 1
– Shaft encoders
– Braking Systems
• Un-Weighted Code
Gray Code
Decimal Gray Binary
0 000 000
1 001 001
2 011 010
3 010 011
4 110 100
5 111 101
6 101 110
7 100 111
Binary to Gray Code Conversion
• To convert binary to gray code following steps are followed
Step1: The most significant bit in gray code is same as the
corresponding MSB in the binary number.
Step 2: Going from left to right, add each adjust pair of binary
code bit to get next gray code bit. Discard Carries.
Binary to Gray Code Conversion
For Example, the conversion of the binary number 10110 to
Gray code :
The gray code is 1101
Gray Code to Binary Conversion
• To convert gray code to binary following steps are followed
Step1: The most significant bit (left most) in binary code is
same as the corresponding MSB in the gray code.
Step 2:Add each binary code generated to the gray code bit in
next adjacent position. Discard carries.
Gray Code to Binary Conversion
For Example, the conversion of the Gray Code 11011 to
binary
The Binary is 10010
Gray Code Application
A A
B B
C C
Binary Gray Code
Alphanumeric Code
• Numbers, Characters, Symbols
• ASCII 7-bit Code
• American Standard Code for Information Interchange
• 10 Numbers (0-9)
• 26 Lower Case Characters (a-z)
• 26 Upper Case Characters (A-Z)
• 32 Control Characters
• Punctuation and Symbols
Alphanumeric Code
• Extended ASCII 8-bit Code
• Additional 128 Graphic characters
• Unicode 16-bit Code
ASCII Code
• Numbers 0 to 9
• ASCII 0110000 (30h) to 0111001 (39h)
• Alphabets a to z
• ASCII 1100001 (61h) to 1111010 (7Ah)
• Alphabets A to Z
• ASCII 1000001 (41h) to 1011010 (5Ah)
• Control Characters
• ASCII 0000000 (0h) to 0011111 (1Fh)
ASCII Code
ASCII Code
Extended ASCII Characters
Error Detection
• Digital Systems are very Reliable
• Errors during storage or transmission
• Parity Bit
– Even Parity
– Odd Parity
Odd Parity Error Detection
• Original data 10011010
• With Odd Parity 110011010
• 1-bit error 110111010
• Number of 1s even indicates 1-bit error
• 2-bit error 110110010
• Number of 1s odd no error indicated
• 3-bit error 100110010
• Number of 1s even indicates error