Binary Code
Binary Code
Binary Code
•EXCESS – 3 CODE
•GRAY CODE
•EBCDIC
•ASCII
1. BCD CODE
•BCD stands for Binary-Coded Decimal.
•This code is also known as 8 4 2 1 code. where this 842 and 1 are
the weights of the 4-bit of the binary code of each decimal digit.
Decimal Symbol Binary BCD BCD
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011 Table:
4 0100 0100 Binary-Coded
5 0101 0101 Decimal(BCD)
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
Example: 1
(4926)10 = (0100100100100110)BCD
EX:2 Convert the decimal number 350 to its
BCD equivalent.
Decimal Number 3 5 0
(350)10 = (001101010000)BCD
EX:3 Convert the decimal number 365 to its BCD
equivalent.
(365)10 = (0011 0110 0101)BCD
Decimal Number 8 7 1
4. BCD enables fast conversions from denary to
binary for applications such as pocket calculators.
Each digit on a calculator corresponds directly to a
four-bit block in BCD.
BCD Addition
(2) Sum <= 9, Final Carry=1 Answer is incorrect, then add 6 (0110)
(3) Sum > 9, Final Carry=0 Answer is incorrect , then add 6 (0110)
Ex: Find the BCD sum of 184+576
184 0001 1000 0100
+ 576 + 0101 0111 0110
0110 1111 1010 invalid BCD code(add 0110)
0110 0110
760 0111 0110 0000 (760)10
Ans= (011101100000)BCD
BCD SUBTRACTION
Step 3: (i) If the final carry is generated then the result is in its true
form. Discard end carry.
There is no end carry. Therefore, the answer is negative and in the 10’s complement
form
Answer = - (10’s complement of 30718)
= -69282
(C ) 72532+ (-3250 )
= 72532
10’s complement of (03250 ) = + 96750
Sum = 169282
Discard the end carry
Answer = 69282
Both the numbers must have the same number of digits ,so we write 3250 as 03250.
Example: subtract 984-599 using 10’s complement.
Example: subtract 984-599 using 9’s complement.
2. EXCESS-3 CODE
Excess-3 code is also treated as XS-3 Code. The Excess-3 code is a
un-weighted & self complementary BCD code used to represent the
decimal numbers.
(24)10 = (01010111)xs-3
(b) 658
Decimal Number 6 5 8
BCD Coded Number 0110 0101 1000
Add 3 0011 0011 0011
1001 1000 1011
(658)10 = (100110001011)xs-3
3. Gray code
•Un weighted Code.
•Unit distance code & Minimum error code.
•It is very useful code in which a decimal number is
represented in binary form in such a way so that each
gray code number differ from the preceding & the
succeeding number by a single bit.
•The Gray code is NOT a BCD code.
DECIMAL BINARY GRAY CODE
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
Table: GRAY CODE
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Binary to Gray Code Conversion
Step 1: Record the MSB as it is.
Step 2: Add the MSB of the binary code to the next bit of binary code, record
the sum and neglect the carry.
Step 3: Repeat the process.
Binary code b3 b2 b1 b0
Gray Code g3 g2 g1 g0
g3=b3 (b3 +b2 ) (b2+b1) (b1+b0)
Ex: Convert binary number to Gray code.
(a) 1011 (b) 1110
Gray code g3 g2 g1 g0
Binary Code b3 b2 b1 b0
g3 = b3 (b3+g2 ) (b2+g1) (b1+g0)
Ex: Convert Gray code to binary code.
(a) 1110 (b) 1001
Ans: (a) 1011 (b) 1110
There are two main coding systems that provide conversions of
keyboard characters into binary:
EBCDIC
ASCII
4. EBCDIC CODE
• EBCDIC stands for Extended Binary Coded Decimal
Interchange Code.
• It uses 8 bits (4 bit for zone , 4 bit for digit) to represent a
symbol in the data.
• It can represent 256 different characters.
• It is used to represent decimal numbers(0-9), lower case
letters(a-z), uppercase letters(A-Z), Special characters, and
control characters(printable and non printable).
• EBCDIC codes are mainly used in the mainframe computer
developed by IBM.
Coding of Alphabetic and Numeric Characters in
Ebcdic
Character Zone Digit
Hence, EBCDIC coding for the word BIT in binary notation will
be
Solution:
Types Of Errors
1. Single Bit Errors
The change in one bit in the whole data sequence , is called “Single bit error”. Occurrence of
single bit error is very rare in serial communication system.
2. Burst Errors
The change of set of bits in data sequence is called “Burst error”. It means two or more bits
in the data unit has changed .The burst error is calculated in from the first bit change to last
bit change.
Error detection codes − are used to detect the errors present in the
received data bit stream. These codes contain some bits, which are
included appended to the original bit stream. These codes detect the error, if it is
occurred during transmission of the original data bit stream.
Example − Parity code, Hamming code.
Here, the number of bits present in the even parity codes is 4. So, the possible even number of ones in these
even parity codes are 0, 2 & 4.
• If the other system receives one of these even parity codes, then there is no error in the received data. The bits
other than even parity bit are same as that of binary code.
• If the other system receives other than even parity codes, then there will be an errors in the received data. In this
case, we can’t predict the original binary code because we don’t know the bit positions of error.
Therefore, even parity bit is useful only for detection of error in the received parity code. But, it is not sufficient
to correct the error.
2. Odd Parity Code:
The value of odd parity bit should be zero, if odd number of ones present in the
binary code. Otherwise, it should be one. So that, odd number of ones present in odd
parity code. Odd parity code contains the data bits and odd parity bit.
The following table shows the odd parity codes corresponding to each 3-bit
binary code. Here, the odd parity bit is included to the right of LSB of binary code.
2P >= n + P +1
Here, n represents the number of bits in the data string.
P represents number of parity bits.
Step 1
Calculate the required number of parity bits.
2P >= n + P + 1 here n = 4
Let P = 2, then
2P = 22 = 4 and n + P + 1 = 4 + 2 + 1 = 7.
2 parity bits are not sufficient for 4 bit data.
So let’s try P = 3, then
2P = 23 = 8 and n + P + 1 = 4 + 3 + 1 = 8
Therefore 3 parity bits are sufficient for 4 bit data.
The total bits in the code word are 4 + 3 = 7
Step 2
Location of parity bit
The parity bits have to be located at the positions of powers of 2.
Here three parity bits to be appended. So (20 ,21 , 22 )i.e. at 1, 2, 4.
So the position of parity bit will be P1 , P2 , P4.
Therefore the codeword after including the parity bits will be like this
D7, D6, D5, P4, D3, P2, P1
Here P1, P2 and P4 are parity bits. D3, D5, D6, D7 are data bits.
Step 3
Determine the parity bits. ( D7, D6, D5, P4, D3, P2 P1 )
( 1 1 0 P4 1 P2 P1 )
For P1 : 3, 5 and 7 bits are having two 1’s so for even parity, P1 = 0.
(For P1 : check 1 bit and skip 1 bit, starting from P1)
For P2 : 3, 6 and 7 bits are having three 1’s so for even parity, P2 = 1.
(For P2 : check 2 bit and skip 2 bit, starting from P2),
For P4 : 5, 6 and 7 bits are having two 1’s so for even parity, P4 = 0.
(For P4 : check 4 bit and skip 4 bit, starting from P4)
By entering / inserting the parity bits at their respective positions, codeword
can be formed and is transmitted. It is
1100110.
Example: If received Hamming code is 1001111 with even
parity . Then detect and correct error.
Step 1
Calculate the required number of parity bits.
2P >= n + P + 1 = (n + P) + 1 = 7+1=8
2P >= 8 = 23
P = 3 Therefore 3 parity bits & 4 bit data.
The total bits in the code word are 4 + 3 = 7.
Step 2
Location of parity bit
The parity bits have to be located at the positions of powers of 2.
Here three parity bits to be appended. So (20 ,21 , 22 )i.e. at 1, 2, 4.
So the position of parity bit will be P1 , P2 , P4.
Therefore the codeword after including the parity bits will be like this
D7, D6, D5, P4, D3, P2, P1
Here P1, P2 and P4 are parity bits. D3, D5, D6, D7 are data bits.
Step 3
Detect the error . ( D7, D6, D5, P4, D3, P2 P1 )
( 1 0 0 1 1 1 1 )
For P1 : 3, 5 and 7 bits are having two 1’s so for even parity, P1 = 1.
(For P1 : check 1 bit and skip 1 bit, starting from P1)
For P2 : 3, 6 and 7 bits are having three 1’s so for even parity, P2 = 1.
(For P2 : check 2 bit and skip 2 bit, starting from P2),
For P4 : 5, 6 and 7 bits are having two 1’s so for even parity, P4 = 0.
(For P4 : check 4 bit and skip 4 bit, starting from P4)
Step 4:
Correction of error : The Decimal value of check bits(new parity bit) gives the position of error in
received hamming code.
P4 P2 P1 = (011)2 = (3)10
There , the error present in third bit(b3) of Hamming code. Just complement the value present in that
bit and remove parity bits in order to get the original binary code.
Corrected data = 1001011