You are on page 1of 40

BINARY CODES

DHARITA K. PATEL
EED, BVM
• In the coding, when numbers, letters or words are
represented by a specific group of symbols, it is said
that the number, letter or word is being encoded.
• The group of symbols is called as a code.
• The digital data is represented, stored and
transmitted as group of binary bits. This group is also
called as binary code.
• The binary code is represented by the number as well
as alphanumeric letter.
Advantages of Binary Code

• Binary codes are suitable for the computer applications.


• Binary codes are suitable for the digital communications.
• Binary codes make the analysis and designing of digital
circuits easier if we use the binary codes.
• Since only 0 & 1 are being used, implementation
becomes easy.
Classification of binary codes
Weighted Codes
• Weighted binary codes are those binary codes which obey
the positional weight principle.
• Each position of the number represents a specific weight.
• Types:
8421 Codes
2421 Codes
5211 Codes
8421 Code or BCD Code
DECIMAL NUMBER BINARY NUMBER 4 BIT EXPRESSION(8421)

0 0 0000

1 1 0001

2 10 0010

3 11 0011

4 100 0100

5 101 0101

6 110 0110

7 111 0111

8 1000 1000

9 1001 1001
2421 Code
DECIMAL NUMBER BINARY NUMBER 2421 CODE

0 0 0000
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 1011
6 110 1100
7 111 1101
8 1000 1110
9 1001 1111
5211 Code
DECIMAL NUMBER BINARY NUMBER 5211 CODE

0 0 0000
1 1 0001
2 10 0011
3 11 0101
4 100 0111
5 101 1000
6 110 1010
7 111 1100
8 1000 1110
9 1001 1111
Reflective Code
• In 2421 and 5211 codes, the code for decimal 9 is the complement of the code for
decimal 0, the code for decimal 8 is the complement of the code for decimal 1, the code
for decimal 7 is the complement of the code for decimal 2, the code for decimal 6 is the
complement of the code for decimal 3, the code for decimal 5 is the complement of the
code for decimal 4. These codes are called as Reflective Codes.
DECIMAL NUMBER BINARY NUMBER 2421 CODE 5211 CODE

0 0 0000 0000
1 1 0001 0001
2 10 0010 0011
3 11 0011 0101
4 100 0100 0111
5 101 1011 1000
6 110 1100 1010
7 111 1101 1100
8 1000 1110 1110
9 1001 1111 1111 NOTE: 8421 code is not a reflective code.
Sequential Codes
• In sequential codes, each succeeding code is one binary number greater than
its preceding code, which greatly helps in manipulation of mathematical data.
• The 8421 and Excess-3 codes are examples of sequential codes.
• 2421 and 5211 codes do not come under sequential codes.
DECIMAL BINARY
8421 CODE EXCESS-3
NUMBER NUMBER

0 0 0000 0011
1 1 0001 0100
2 10 0010 0101
3 11 0011 0110
4 100 0100 0111
5 101 0101 1000
6 110 0110 1001
7 111 0111 1010
Non-Weighted Codes
• Codes will not follow the weights of the
sequence binary numbers these are called as
non-weighted codes.
• ASCII code and Gray code are some of the
examples where they are coded for some special
purpose applications and they do not follow the
weighted binary number calculations.
Excess-3 Code
• The excess – 3 code of a decimal number is achieved by adding the
number 3 to the 8421 code.
• For example to convert 15 to an excess-3 code, first 3 to be added to
each digit as shown below.
• Find the excess-3 code of (237.75)10
• The excess-3 code for (237)10 is obtained by adding 3 to all the digits
individually, that is 2, 3 and 7 will become 5, 6 and 10 respectively.
These 5, 6 and 10 decimals have to be converted into binary form and
the result is 010101101010.
• The excess-3 code for (.75)10 is obtained by replacing 7 and 5 with 10
and 8 respectively by adding 3 to each digit. That is, the excess-3 code
for (.75)10 is .10101000.
• Combining the results of the integral and fractional parts, the excess-
3 code for (237.75)10 is 010101101010.10101000.
• Find the decimal number of excess-3 number
110010100011.01110101.
• The excess-3 code is 110010100011.01110101
• By separating 4 bits as group the equivalent excess-3 code is given
as 1100 1010 0011.0111 0101.
• Subtracting 0011 from each four-bit group, we obtain the new
number as: 1001 0111 0000.0100 0010.
• Therefore, the decimal equivalent is (970.42)10.
Gray Code
• The gray code is the code where one bit will be differed to the preceding
number.
• The gray code has very special place in digital electronics.
• This is because, bit patterns for every consecutive number differ in only
one bit position. These codes are also called cyclic codes.
• It is also called as Unit Distance Code.
How to find a gray code from the given binary
number?
• Write the MSB of the given binary code as the MSB of gray code and
binary code are same.
• Perform an Ex-OR operation with the previous bit and the current bit
to get the next gray digit. Ignore the carry, if any.
• Repeat 2nd step until all the binary bits have been Ex-ORed with their
previous one.
Convert a binary number (101011)2 into its
equivalent gray code.
DECIMAL NUMBER BINARY CODE GRAY CODE

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

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000
DECIMAL NUMBER BINARY CODE GRAY CODE

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

10 1010 1111

11 1011 1110

12 1100 1010

13 1101 1011

14 1110 1001

15 1111 1000
a) Consider an application where 3- bit binary code is provide to indicate
position of the rating disk with the help of brushes.
b) When brushes are on the black position, they output a 1. When on the
white position, they output a 0.
c) Now, consider what happen when the brushes are on 111 sector and
almost to enter 000 sector.
d) If one brushes slightly ahead to other, say the 3rd brush, then the position
indicated 011 instead of 000 or 111. This, result in 180 degree error in the
disk position.
e) Since it is physically impossible to have all the brushes precisely aligned,
some error will always be present at the edge of sector.
f) If we use Gray code to represent disk position then error due to improper
brush alignment can be reduced. This is because the gray code assures that
only one bit will change at one time the decimal number is incremented.
So, in 3- bit code, error may occur due to one bit position. Other two bit
position of two adjacent sector are always same and hence no possibility of
error.
Alphanumeric codes
• A complete alphanumeric code would include the 26 lowercase
characters, 26 uppercase characters, 10 numeric digits, etc.
• Input-output devices such as keyboards, monitors, and mouses can be
interfaced using these codes.
• Two well accepted code sets are used for information coding:
o EBCDIC code: Extended binary coded decimal interchange code. (IBM computers)
o ASCII Code: American standard code for information interchange
The ASCII code is a seven-bit code, and so it has 128 possible code groups.
Error Detection and
Correction Code

• Plays an important role in the transmission of data from one source to


another.
• The noise also gets added into the data when it transmits from one
system to another, which causes errors in the received binary data at
other systems. The bits of the data may change(either 0 to 1 or 1 to 0)
during transmission.
• It is impossible to avoid the interference of noise, but it is possible to get
back the original data.
• For this purpose, we first need to detect either an error z is present or
not using error detection codes. If the error is present in the code, then
we will correct it with the help of error correction codes.
Error detection code
• The error detection codes are the code used for detecting the error in
the received data bitstream.
• In these codes, some bits are included appended to the original
bitstream.
• Error detecting codes encode the message before sending it over the
noisy channels.
• The encoding scheme is performed in such a way that the decoder at
the receiving can find the errors easily in the receiving data with a
higher chance of success.
Parity Code
• In parity code, we add one parity bit either to the right of the LSB or left to the MSB to
the original bitstream.
• Parity check is also called as “Vertical Redundancy Check (VRC)”.
• There are two types of parity bits in error detection:
Even parity
Odd parity
• Even Parity
If the data has even number of 1’s, the parity bit is 0. Ex: data is 10000001 -> parity bit 0
Odd number of 1’s, the parity bit is 1. Ex: data is 10010001 -> parity bit 1
• Odd Parity
If the data has odd number of 1’s, the parity bit is 0. Ex: data is 10011101 -> parity bit 0
Even number of 1’s, the parity bit is 1. Ex: data is 10010101 -> parity bit 1
• NOTE: The counting of data bits will include the parity bit also.
Check Sum
• Checksums are similar to parity bits except, the number of bits in the
sums is larger than parity and the result is always constrained to be
zero.
• That means if the checksum is zero, error is detected.
• A checksum of a message is an arithmetic sum of code words of
certain length.
• The sum is stated by means of 1’s compliment and stored or
transferred as a code extension of actual code word.
• At receiver a new checksum is calculated by receiving the bit sequence
from transmitter.
• For example, if we have 4 bytes of data as 25h, 62h, 3fh, 52h.
• Then, adding all bytes we get 118H
• Dropping the carry Nibble, we get 18H
• Find the 2’s complement of the nibble, i.e. E8H
• This is the checksum of the transmitted 4 bits of data.
• At receiver side, to check whether the data is received without error
or not, just add the checksum to the actual data bits (we will get
100H).
• By dropping the carry nibble we get 00H. This means the checksum is
constrained to zero. So there is no error in the data.
Cyclic Redundancy Check (CRC)
• The Cyclic Redundancy Checks (CRC) is the most powerful method for
Error-Detection and Correction.
• It is given as a kbit message and the transmitter creates an (n – k) bit
sequence called frame check sequence.
• The out coming frame, including n bits, is precisely divisible by some fixed
number.
• Modulo 2 Arithmetic is used in this binary addition with no carries, just like
the XOR operation.
• Redundancy means duplicacy. The redundancy bits used by CRC are
changed by splitting the data unit by a fixed divisor.
• The remainder is CRC.
• These types of codes are used for error detection and encoding.
Process
• A string of n 0s is added to the data unit. The number n is one smaller
than the number of bits in the fixed divisor.
• The new data unit is divided by a divisor utilizing a procedure known
as binary division; the remainder appearing from the division is CRC.
• The CRC of n bits interpreted in phase 2 restores the added 0s at the
end of the data unit.
Example

Message D = 1010001101 (10 bits)


Predetermined P = 110101 (6 bits)
FCS R = to be calculated 5 bits
Hence, n = 15 K = 10 and (n – k) = 5
The message is generated through 25:
accommodating 10100011010000
The product is divided by P.
The remainder is inserted to 25D to
provide T = 101000110101110 that is
sent.
Suppose that there are no errors, and
the receiver gets T perfect. The
received frame is divided by P.

Because of no remainder, there are no


errors.
CRC generator and checker
Error Correcting Codes
• The codes which are used for both error detecting and error correction are
called as “Error Correction Codes”. The error correction techniques are of
two types:
• Single bit error correction
• Burst error correction
• The process or method of correcting single bit errors is called “single bit
error correction”. The method of detecting and correcting burst errors in
the data sequence is called “Burst error correction”.
• Hamming code or Hamming Distance Code is the best error correcting code
we use in most of the communication network and digital systems.
Hamming Code
• Hamming code is an error correction system that can detect and
correct errors when data is stored or transmitted.
• It requires adding additional parity bits with the data.
• It is commonly used in error correction code.
• Whenever data is transmitted or stored, it's possible that the data
may become corrupted.
• This can take the form of bit flips, where a binary 1 becomes a 0 or
vice versa.
• Error correcting codes seek to find when an error is introduced into
some data.
• This is done by adding parity bits, or redundant information, to the
data.
• Hamming code uses a block parity mechanism. The data is divided into
blocks, and parity is added to the block. Hamming code can correct
single-bit errors and detect the presence of two-bit errors in a data
block.
• The amount of parity data added to Hamming code is given by the
formula 2p ≥ d + p + 1, where p is the number of parity bits and d is the
number of data bits. For example, if you wanted to transmit 7 data bits,
the formula would be 24 ≥ 7 + 4 + 1, so 4 parity bits are required.
• The type of error correcting is given as the name of the algorithm, the
total number of bits in the block and then the number of effective data
bits. Therefore, Hamming encoding with 4 data bits and 3 parity bits for
a total of 7 total bits is given as Hamming(7,4).
The general process to make a Hamming code
is as follows.
• Find the total block length with both data bits and parity bits.
• Number each bit with its binary value.
• Each value with only a single binary 1 and the remaining digits 0s (powers
of 2) become parity bits. All other bits are data bits.
• Each parity bit covers all data bits that have the parity bit's value set to 1.
Put another way, where the data bit value is AND checked to the parity bit
value it is greater than one:
• For example, parity bit 1 (001) covers data bit 3 (011), bit 5 (101) and bit 7 (111).
• Parity bit 2 (010) covers data bit 3 (011), bit 6 (110) and bit 7 (111).
• Parity bit 4 (100) covers data bit 5 (101), bit 6 (110) and bit 7 (111).
• Set the parity bit equal to 1 if all the values of its data bits are odd; set it to
0 if the total number is even.
Thank you

You might also like