Binary Codes
Binary Codes
Contents:
• Definition
• Classification
• Examples
BINARY CODES:
1. Weighted Codes
2. Non-Weighted Codes
3. Binary Coded Decimal Code
4. Alphanumeric Codes
Weighted Codes:
1.The Most Significant Bit (MSB) of the binary code is always equal
to the MSB of the given gray code.
2.Other bits of the output binary code can be obtained by checking
the gray code bit at that index. If the current gray code bit is 0, then
copy the previous binary code bit, else copy the invert of the
previous binary code bit.
Binary Coded Decimal (BCD) code:
• In this code each decimal digit is represented by a 4-bit binary
number.
• BCD is a way to express each of the decimal digits with a binary
code.
• In the BCD, with four bits we can represent sixteen numbers
(0000 to 1111).
• But in BCD code only first ten of these are used (0000 to 1001).
• The remaining six code combinations i.e. 1010 to 1111 are
invalid in BCD.
Alphanumeric codes:
•In case of even parity: If number of 1s is even then parity bit value
is 0. If number of 1s is odd then parity bit value is 1.
•In case of odd parity: If number of 1s is odd then parity bit value is
0. If number of 1s is even then parity bit value is 1.
Parity Bit Data Bits
Odd Parity:
Odd Parity:
Parity Bit Data Bits
1 1 1 1 0 0 1 0
Checksum:
i.e., 1 0 1 0 1 0 0 1 0 0 1 1 1 0 0 1 00011101
(Databits) (Checksum)
At the receiver end:
The following steps will be implemented at the receiver end.
Step1: Now divide the given input into two frames each contains
equal number of bits. Let us consider it as follows:
F1: 1 0 1 0 1 0 0 1
F2: 0 0 1 1 1 0 0 1
Step2: Perform binary addition F1+ F2 + Checksum
F1: 1 0 1 0 1 0 0 1
F2: 0 0 1 1 1 0 0 1
Checksum: 0 0 0 1 1 1 0 1
-------------------
F1+F2+CS=1 1 1 1 1 1 1 1
-------------------
Step3: Now take 1’s complement for the above result.
Resultant = 0 0 0 0 0 0 0 0
As the resultant of 1’s complement is all zeros, we can conclude
that there is no error in the data shared by the sender, otherwise it
will be treated as error.
CRC: (Cyclic Redundancy Check)
• The binary data is first augmented by adding k-1 zeros in the end
of the data
• Use modulo-2 binary division to divide binary data by the key
and store remainder of division.
• Append the remainder at the end of the data to form the encoded
data and send the same
Receiver Side (Check if there are errors introduced in
transmission):
Modulo 2 Division:
The process of modulo-2 binary division is the same as the familiar
division process we use for decimal numbers. Just that instead of
subtraction, we use XOR here.
In each step, a copy of the divisor (or data) is XORed with the k bits
of the dividend (or key).
The result of the XOR operation (remainder) is (n-1) bits, which is
used for the next step after 1 extra bit is pulled down to make it n bits
long.
When there are no bits left to pull down, we have a result. The (n-1)-
bit remainder which is appended at the sender side.
Illustration:
Example 1 (No error in transmission):
Sender Side: