BCD Code
BCD Code
Amraja Shivkar
BCD(Binary Coded Decimal) Code
• In this code each digit is represented by a 4-bit binary number.
• The positional weights assigned to the binary digits in BCD code are 8-4-2-1 with 1
corresponding to LSB and 8 corresponding to MSB.
Positional 8 4 2 1
Weights 23 22 21 20
MSB LSB
• Other BCD codes like 7-4-2-1, 5-4-2-1 etc also exist.
Decimal equivalent → 0 7 9
Therefore (1010 0011 1100)XS-3 = (709)10
--------------------------------------------------------------------------------------------------------------
Obtain XS-3 equivalent of following numbers:
(a) (235)10 (b) (146)10 (c) (0111 1000)BCD (d) (1001 0011)BCD
(e) (101010)2 (hint: first convert to decimal)
Gray Code
Decimal Binary Gray Code
• Non-weighted code.
0 0000 0000
• It has a very special feature that only
1 0001 0001 one bit will change, each time the
2 0010 0011 decimal number is incremented,
3 0011 0010 therefore also called unit distance code.
4 0100 0110
5 0101 0111 Binary and Gray conversions:
6 0110 0101 • For Gray to binary or binary to Gray
7 0111 0100
conversions let’s understand rules for
Ex-OR
8 1000 1100
(Ex-OR is represented by symbol )
9 1001 1101
10 1010 1111 Rules for EX-OR:
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Conversion from Binary to Gray code:
Step 1: Write MSB of given Binary number as it is.
Step 2: Ex-OR this bit with next bit of that binary number and write the result.
Step 3: Ex-OR each successive sum until LSB of that binary number is reached.
• Eg.: Convert (1010011)2 to its equivalent Gray code.
1 0 1 0 0 1 1
1 1 1 1 0 1 0
Therefore (1010011)2 = (1111010)Gray
Conversion from Gray to Binary:
Step 1: Write MSB of given Binary number as it is.
Step 2: Ex-OR this bit with next bit of that binary number and write the result.
Step 3: Continue this process until LSB of that binary number is reached.
• Eg.: Convert (1010111)Gray to its equivalent Binary number.
1 0 1 0 1 1 1
1 1 0 0 1 0 1
Therefore (1010111)Gray = (1100101)2