Lect3 - Types of Binary Codes
Lect3 - Types of Binary Codes
Binary codes are codes which are represented in binary system with modification from
the original ones. Below we will be seeing the following: Weighted codes and Non-
Weighted codes Weighted binary codes Weighted binary codes are those which obey
the positional weighting principles, each position of the number represents a specific
weight. The binary counting sequence is an example.
2421 code
This is a weighted code; its weights are 2, 4, 2 and 1. A decimal number is represented
in 4-bit form and the total four bits weight is 2 + 4 + 2 + 1 = 9. Hence the 2421 code
represents the decimal numbers from 0 to 9.
5211 code
This is a weighted code; its weights are 5, 2, 1 and 1. A decimal number is represented
in 4-bit form and the total four bits weight is 5 + 2 + 1 + 1 = 9. Hence the 5211 code
represents the decimal numbers from 0 to 9.
Self-Complementing Codes
A code is said to be self-complementing if the code word of 9’s complement of N i.e. 9 –
N, can be obtained from the code word of N by interchanging all the 1’s and 0’s.
Eample : In (642-3) code
decimal 3 is represented by 1001, while decimal 6 is represented by 0110.
Reflective code
A code is said to be reflective when code for 9 is complement for the code for 0, and so
is for 8 and 1 codes, 7 and 2, 6 and 3, 5 and 4. Codes 2421, 5211, and excess-3 are
reflective, whereas the 8421 code is not.
Sequential code
A code is said to be sequential when two subsequent codes, seen as numbers in
binary representation, differ by one. This greatly aids mathematical manipulation of
data. The 8421 and Excess-3 codes are sequential, whereas the 2421 and 5211 codes
are not.
Non-Weighted code
Non weighted codes are codes that are not positionally weighted. That is, each position
within the binary number is not assigned a fixed value.
Excess-3 code
Excess-3 is a non weighted code used to express decimal numbers. The code derives
its name from the fact that each binary code is the corresponding 8421 code plus
0011(3). Example: 1000 of 8421 = 1011 in Excess-3
Gray code
The Gray code was designed by Frank Gray at Bell Labs, patented the code in 1947.
The gray code belongs to a class of codes called minimum change codes, in which only
one bit in the code changes when moving from one code to the next. The Gray code is
non-weighted code, as the position of bit does not contain any weight. The gray code is
a reflective digital code which has the special property that any two subsequent
numbers codes differ by only one bit. This is also called a unit-distance code. In digital
Gray code has got a special place. It is an unweighted binary code in which two
successive values differ only by 1 bit. Owing to this feature, the maximum error that can
creep into a system using the binary Gray code to encode data is much less than the
worst-case error encountered in the case of straight binary encoding. Table 2.3 lists the
binary and Gray code equivalents of decimal numbers 0–15.
An examination of the four-bit Gray code numbers, as listed in Table below, shows that
the last entry rolls over to the first entry. That is, the last and the first entry also differ by
only 1 bit. This is known as the cyclic property of the Gray code. Although there can
be more than one Gray code for a given word length, the term was first applied to a
specific binary code for non-negative integers and called the binary-reflected Gray
code or simply the Gray code.
Binary 1011
Gray code 1- - -
Binary 1011
Gray code 11- -
Binary 1011
Gray code 111-
Binary 1011
Gray code 1110
A given Gray code number can be converted into its binary equivalent by going through
the following steps:
Begin with the most significant bit (MSB). The MSB of the binary number is the
same as the MSB of the Gray code number.
The bit next to the MSB (the second MSB) in the binary number is obtained by
adding the MSB in the binary number to the second MSB in the Gray code
number and disregarding the carry(modulo 2 sum), if any.
The third MSB in the binary number is obtained by adding the second MSB in the
binary number to the third MSB in the Gray code number. Again, carry, if any, is
to be ignored.
The process continues until we obtain the LSB of the binary number.
Example : step-by-step conversion of the Gray code number 1110 into its binary
equivalent:
Parity bit
In parity codes, every data byte, or nibble (according to how user wants to use it) is
checked if they have even number of ones or even number of zeros. Based on this
information an additional bit is appended to the original data. Thus if we consider 8-bit
data, adding the parity bit will make it 9 bit long. At the receiver side, once again parity
is calculated and matched with the received parity (bit 9), and if they match, data is ok,
otherwise data is corrupt.
Odd Parity: Checks if there is an odd number of ones; if so, parity bit is zero. When
number of ones is even then parity bit is set to 1.
Hamming codes
Hamming code adds a minimum number of bits to the data transmitted in a noisy
channel, to be able to correct every possible one-bit error. It can detect (not correct)
two-bit errors and cannot distinguish between 1-bit and 2-bits inconsistencies. It can't -
in general - detect 3(or more)-bits errors.
Alphanumeric codes
The binary codes that can be used to represent all the letters of the alphabet, numbers
and mathematical symbols, punctuation marks, are known as alphanumeric codes or
character codes. These codes enable us to interface the input-output devices like the
keyboard, printers, video displays with the computer.
ASCII codes
ASCII stands for American Standard Code for Information Interchange. It has become a
world standard alphanumeric code for microcomputers and computers. It is a 7-bit code
representing 27 = 128 different characters. These characters represent 26 upper case
letters (A to Z), 26 lowercase letters (a to z), 10 numbers (0 to 9), 33 special characters
and symbols and 33 control characters.
EBCDIC codes
EBCDIC stands for Extended Binary Coded Decimal Interchange. It is mainly used with
large computer systems like mainframes. EBCDIC is an 8-bit code and thus
accommodates up to 256 characters. An EBCDIC code is divided into two portions: 4
zone bits (on the left) and 4 numeric bits (on the right).