Sunteți pe pagina 1din 15

BINARY / DIGITAL CODES

DLDby Dr. Muhammad TahaJilani 1


Binary Coded Decimal (BCD)
• Binary coded decimal (BCD) is a way to express each
of the decimal digits with a binarycode.
• There are only ten code groups in the BCDsystem, so
it is very easy to convert between decimaland BCD.
• Since, we like to read and write indecimal, it
provides an excellent interface to binary systems
Apps:
Digital clocks, digital thermometers, digital
meters, and other devices with seven-
segment displays typically use BCDcode to
simplify the displaying of decimal numbers.
Useful, where limited processing is required
DLDby Dr. Muhammad TahaJilani 2
Binary Coded Decimal (BCD)
• The 8421 code is a type of BCD (binary coded decimal)
code. Binary coded decimal means that each decimal
digit, 0 through 9, is represented by a binary code of
four bits.
• The designation 8421 indicates the binary weights of
the four bits (23, 22, 21,20).
• The ease of conversion between 8421 code numbers
and the familiar decimal numbers is the main
advantage of this code.
• All you have to remember are the ten binary
combinations that represent the tendecimal digits

DLDby Dr. Muhammad TahaJilani 3


8241 Binary Coded Decimal (BCD)

Observed anything?
Similar to HEX, but after 9 therewill
be no output
Note:
You should realize that, with four bits, sixteen numbers (0000
through 1111) can be represented but that, in the 8421 code,
only ten of these areused.
The six code combinations that are not used—1010, 1011,1100,
1101, 1110, and 1111

DLDby Dr. Muhammad TahaJilani 4


Decimal number Binary number Binary Coded Decimal(BCD)

0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 1010 0001 0000
11 1011 0001 0001
12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101
Decimal-to-BCD
• Start at the right-most bit and break the code
into groups of four bits.
• Then write the decimal digit representedby
each 4-bit group.

DLDby Dr. Muhammad TahaJilani 6


BCD-to-Decimal
• Reverse procedure

DLDby Dr. Muhammad TahaJilani 7


BCDAddition
• Step 1: Add the two BCDnumbers, using same rules, as
in binary addition.
• Step 2: If a 4-bit sum is equal to or less than 9 (1001), it
is a valid BCDnumber.
• Step 3: If a 4-bit sum is greater than 9 (=/> 1010), or if a
carry out of the 4-bit group is generated, it is an invalid
result.

DLDby Dr. Muhammad TahaJilani 8


BCDAddition
Add BCDnumbers:
110 + 299 ?

0001 0001 0000


0010 1001 1001
0011 1010 1001
Valid Invalid Valid

DLDby Dr. Muhammad TahaJilani 9


BCDMaking >9 Sum Valid
GRAY CODES

DLDby Dr. Muhammad TahaJilani 11


Gray code

DLDby Dr. Muhammad TahaJilani 12


Gray Codes
Easy tip to get BCD/BinaryCode into Gray Code
• Two simple steps:
1. Copy the MSB as it is, from Binary, that will be the1st bit
of Graycode
2. Now add Binary MSB with the next bit, this will be the 2nd
bit in Gray code. Repeat this for all pair of binary code
bits and discard the carries
Add all pairs Add all pairs, Discardcarries
1+1=0 1+0=1
Examples: 0+0=0 1+0=1

• Binary Number = 0 0 1 0 1110


Copy MSB 1+1=0
0+1=1

• Gray Code = 0 0 11 1 0 01

DLDby Dr. Muhammad TahaJilani 13


Gray Codes
• Same procedure for BCDto Gray codetable

DLDby Dr. Muhammad TahaJilani 14


Gray Codes
• Same procedure for BCDto Gray codetable

DLDby Dr. Muhammad TahaJilani 15

S-ar putea să vă placă și