Binary coded decimal numbers
This is the method of representing
decimal numbers using binary digits.
There are 10 symbols in decimal number
system , each of these symbols is represented by a unique string
consisting of two symbols of binary number system. A four bit binary
digit is used for each decimal symbol because with three bit binary
digit we can only represent 2^3 =8 digits.
Eg Decimal number 15 if converted to
binary becomes 1111. But when 15 is encoded binary it becomes 0001
0101 . 0001 representing 1 and 0101 representing 5.
The look up table for encoding decimal
number is shown below.
Decimal digit
|
Binary code
|
0
|
0000
|
1
|
0001
|
2
|
0010
|
3
|
0011
|
4
|
0100
|
5
|
0101
|
6
|
0110
|
7
|
0111
|
8
|
1000
|
9
|
1001
|
Encoding to binary is faster than
conversion to binary because it is just plain look up to the
conversion table and replacing, while conversion involves repeated
division which make the
it slow. On an average log(10)2 =3.32
bits are required when decimal numbers are converted to binary. 4 bit
s are needed when decimal is encoded. The (4/3.32)=1.2 is the measure
of the extra bits needed to store encoded numbers.
We need at-least 4 bits to represent a
decimal digit. But there is 16 four bit groups and we need only 10
of these 16 for encoding decimal digits. There is 16!/6! permutations
of selecting 10 out of 16 items. Most of the possible 3*10^10 codes
are not useful, only a small numbers is chosen are used and chosen
according to ease in arithmetic, error correction properties, ease in
coding etc. The useful code are divided into four classes .They are
1.Weighted codes
2.Self complementing codes
3.Cyclic,reflected or Gray codes
Weighted
codes
Weighted code examples
Decimal Digit
|
Weights
|
Weights
|
Weights
|
|
8 4 2 1
|
8 4 -2
-1
|
2 4 2 1
|
0
|
0 0 0 0
|
0 0 0 0
|
0 0 0 0
|
1
|
0 0 0 1
|
0 1 1 1
|
0 0 0 1
|
2
|
0 0 1 0
|
0 1 1 0
|
0 0 1 0
|
3
|
0 0 1 1
|
0 1 0 1
|
0 0 1 1
|
4
|
0 1 0 0
|
0 1 0 0
|
0 1 0 0
|
5
|
0 1 0 1
|
1 0 1 1
|
1 0 1 1
|
6
|
0 1 1 0
|
1 0 1 0
|
1 1 0 0
|
7
|
0 1 1 1
|
1 0 0 1
|
1 1 0 1
|
8
|
1 0 0 0
|
1 0 0 0
|
1 1 1 0
|
9
|
1 0 0 1
|
1 1 1 1
|
1 1 1 1
|
As you can see from the table the
decimal value of the code is the algebraic sum of the weights of the
columns in which 1 appears.
d=∑w(i)b(i)
I shall explain this with the help of
and example.
7=0*8 + 1*4 + 1*2 + 1*1
7=1*8 +0*4 + 0 *-2+ 1*-1
7=1*2+ 1*4+ 0*2 + 1*1
The weights may be negative, negative
weights can be represented by a over bar or by a – sign. The same
weights can repeated twice like in (2,4,2,1) code. The weights should
be chosen in such a way that it they should be able to represent all
the digits from 0-9.
The first 10 groups of 4 bits represent
0 to 9, the remaining 6 are illegal combinations and may be used for
error detection.
Self-complementing
codes
Here
the code is made in such a manner that if we replace the 0s by 1 and
1s by zero we get the code for 9-d. The table below shows some self
complimenting codes.
d
|
Code for d
|
Code for 9-d
|
9-d
|
2421
|
2421
|
0
|
0000
|
1111
|
9
|
1
|
0001
|
1110
|
8
|
2
|
0010
|
1101
|
7
|
3
|
0011
|
1100
|
6
|
4
|
0100
|
1011
|
5
|
5
|
1011
|
0100
|
4
|
6
|
1100
|
0011
|
3
|
7
|
1101
|
0010
|
2
|
8
|
1110
|
0001
|
1
|
9
|
1111
|
0000
|
0
|
A
condition for self-complementing code is that the sum should be be
nine(2+4+2+1=9).
There
are self complimenting codes which are not weighted, excess three
code is an example. For making a excess three code the number is
taken in BCD form first . Then binary three(4 bit) is added to every
four bit groups .
Eg
find the excess three code of 739.
BCD
code of 739= 0111 0011 1001 .
Adding
binary 3(0011) to every four bit groups of the BCD representation of
739
0111
0011 1001
+0011
0011 0011
---------------------
1010
0110 1100
So
excess three code for 739 is 1010 0110 1100.
Gray
code,Reflected codes or Cyclic codes.
Hamming
distance between two equal length binary sequences is the number of
positions they differ in. Eg A= 0110 B=1010 , the hamming distance
between them 2.
In
cyclic code the adjacent code groups differ from each other by only
one bit. Hamming distance between two successive code group in a
cyclic code is unity.
The
counting
sequences
in
base-10,
binary
and
Gray
codes
go
as
shown
below.
Base-10
|
Binary
|
Gray
|
0
|
0000
|
0000
|
1
|
0001
|
0001
|
2
|
0010
|
0011
|
3
|
0011
|
0010
|
4
|
0100
|
0110
|
5
|
0101
|
0111
|
6
|
0110
|
0101
|
7
|
0111
|
0100
|
8
|
1000
|
1100
|
9
|
1001
|
1101
|
In
each subsequent number in gray code only the lowest bit possible is
changed.