DLD3
DLD3
we will introduce four different codes where 4 bits are used to represent a single
decimal digits and/or characters.
Binary Coded Decimal (BCD)
The binary system is the natural one for computers but people are accustomed to decimal
system.
For this to be resolved we need to convert all decimals to binary then do all the arithmetic
operations then return them to decimal. It will be easier to represent directly decimals in binary
bits so we can do arithmetic operations directly.
A set of 4 elements can be coded with 2 bits. The combinations
of n-bit code are from 0 to 2n-1. Decimal BCD
A set of 10 elements can be coded with 4 bits. The combinations Equivalent Digit
of 4-bit code are from 0 to 15. 6 out of the 16 combinations 0 0000
are unassigned.
1 0001
A number of n decimal digits will require 4n bits in BCD.
2 0010
3 0011
(396)10=(??????????????)BCD
4 0100
(396)10=(0011 1001 0110)BCD
5 0101
6 0110
(185)10= (??????????????)BCD
7 0111
(185)10= (??????????????)2
8 1000
(185)10= (0001 1000 0101)BCD= (10111001)2
9 1001
Addition in BCD
How can we add two BCD numbers??
Since each decimal digit can’t hold more than 9 then the maximum sum of 2 digits is 9+9+1
where 1 is for carry from lower significant digit. Then the result is between 0 and 19.
In binary this is between 0000 to 10011 but in BCD it should be 0000 to 1 1001.
(448)10+(489)10=(????)10 (448)10+(489)10=(937)10
Column # 5 4 3 2 1 Column # 5 4 3 2 1
Carries 0 0 0 1 Carries 0 0 0
1st number 0 1 0 0 1st number 1 0 0 0
2nd number + 1 0 0 0 2nd number + 1 0 0 1
1 1 0 1 1 0 0 0 1
0 1 1 0 0 1 1 0
Sum 1 0 0 1 1 Sum 1 0 1 1 1
Column # 5 4 3 2 1
Carries 0 0 0 1
1st number 0 1 0 0
2nd number + 0 1 0 0
Sum 1 0 0 1
Excess-3 Code
The excess 3 code for a decimal digit is the binary combination of the decimal digit plus 3. The
code has desirable properties when implementing decimal subtraction.
Column # 5 4 3 2 1 Column # 5 4 3 2 1
Carries 0 0 0 1 Carries 0 0 0
1st number 1 0 0 0 1st number 1 0 0 1
2nd number + 1 0 1 0 2nd number + 1 1 0 0
1 0 0 1 1 1 0 1 0 1
+ 0 0 1 1 + 0 0 1 1
Sum 1 0 1 1 0 Sum 1 1 0 0 0
Column # 5 4 3 2 1
Carries 0 0 0 1
1st number 0 1 1 0
(356)10+(579)10=(935)10
2nd number + 1 0 0 0
1 1 1 1
- 0 0 1 1
Sum 1 1 0 0
Excess-3 Code
Column # 5 4 3 2 1 Column # 5 4 3 2 1
Borrow 1 1 0 Borrow 0 1 1
1st number 1 0 0 0 1st number 1 1 0 0
2nd number - 1 0 1 0 2nd number - 1 0 0 1
1 1 1 0 0 0 1 1
- 0 0 1 1 + 0 0 1 1
Sum 1 0 1 1 Sum 0 1 1 0
Column # 5 4 3 2 1
Borrow 1 1 0 1
1st number 1 0 0 1
(659)10-(376)10=(283)10
2nd number - 0 1 1 0
0 0 1 0
+ 0 0 1 1
Sum 0 1 0 1
2*421 Code
The decimal digits are divided into two groups . The first five digits with 0 bit on the msb and
the second five with 1 bit on the msb.
SO LONG.
Solution: