Types of Binary Codes
Types of Binary Codes
In weighted binary codes, the positional weights are defined in terms powers of 2. The value
of each bit depends on its position in the binary code. Thus, in a given weighted binary code,
the rightmost bit has the least weight and the leftmost bit has the highest weight.
In general, the weight of nth bit in a weighted binary code is given by,
nth bit = 2n
For example, let a 4-bit weighted binary code 1011. The value of the code is,
1 × 23 + 0 × 2 2 + 1 × 2 1 + 1 × 2 0
1×8+0×4+1×2+1×1
8 + 0 + 2 + 1 = 11
It is clear that the rightmost bit has a positional weight of 2 0 = 1, whereas the leftmost bit
has a positional weight of 23 = 8.
Examples of weighted binary codes are 8421 BCD code, 5211 code, 2421 code, etc.
In non-weighted binary codes, the value of the bit does not depend on the position within the
number. Each bit position has an equal positional value.
Examples of non-weighted binary codes include Excess-3 code and Gray code.
Excess-3 Code
Excess-3 code is also called as XS-3 code. It is a type of non-weighted code used to express
decimal numbers. Excess-3 code words are derived from the 8421 BCD code words adding
(0011)2 or (3)10 to each code word in 8421.
Gray Code
Gray codes are a type of non-weighted code. They are not arithmetic codes, which means
there are no specific weights assigned to the bit position.
Gray codes have a very special feature that, only one bit will change each time the decimal
number is incremented (see the figure below). As only one bit changes at a time, gray codes
are also known unit distance code.
Gray codes are cyclic codes and they cannot be used in arithmetic operation.
Gray codes are popularly used in Shaft Position encoders. A shaft position encoder produces
a code word that represents the angular position of the shaft.
Alphanumeric Codes
A binary digit or bit can represent only two states '0' or '1'. But this is not enough for
communication between two computers because there we need many more symbols for
communication. These symbols are required to represent 26 alphabets with capital and small
letters, numbers from 0 to 9, punctuation marks and other symbols.
Alphanumeric codes are the codes that represent numbers and alphabetic characters. Mostly
such codes also represent other characters such as symbol and various instructions
necessary for conveying information.
Alphanumeric codes are binary codes that use character encoding schemes that represent
both numbers and alphabetic characters. Alphanumeric codes are mainly used in
applications involving character representation and information exchange.
Some common examples of alphanumeric codes are ASCII (American Standard Code for
Information Interchange), Extended ASCII, EBCDIC (Extended Binary Coded Decimal
Interchange Code), Unicode, etc.
An alphanumeric code should at least represent 10 digits and 26 letters of the alphabet, i.e.,
total 36 items. The following three alphanumeric codes are very commonly used for data
representation −
ASCII code is a 7-bit code, whereas EBCDIC is an 8-bit code. ASCII code is more commonly
used, while EBCDIC is used primarily in large IBM computers.
Binary Coded Decimal (BCD)
Binary coded decimal or BCD is a binary code used to represent decimal numbers in their
digital format. 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 BCD, each decimal digit
is represented by a unique combination of binary bits.
BCD is mainly used in digital systems where decimal arithmetic operations are performed
like in computers, calculators, display devices, digital sensors, etc.
In BCD, with 4 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.
Error detecting codes are important to ensure integrity in data transmission and storage.
They help in improving the reliability of the system.
Whenever a message is transmitted, it may get scrambled by noise or data may get
corrupted. To avoid this, we use error-detecting codes which are additional data added to a
given digital message to help us detect if an error occurred during transmission of the
message. A simple example of error-detecting code is parity check.
Error-correcting codes deploy the same strategy as error-detecting codes but additionally,
such codes also detect the exact location of the corrupt bit. This allows the receiver to re-
obtain the original data even if some of the bits are corrupted.
In error-correcting codes, parity check has a simple way to detect errors along with a
sophisticated mechanism to determine the corrupt bit location. Once the corrupt bit is
located, its value is reverted (from 0 to 1 or 1 to 0) to get the original message.
Just like error detecting codes, error correcting codes are important to maintain data
integrity in digital communication and data storage applications.
Different types of error correcting codes are used in different digital systems depending on
the type of communication channel, error pattern, degree of error correction, etc. Some
common examples of error correcting codes are Hamming code, Reed-Solomon code, Low-
Density-Parity-Check code, BCH code, etc.
The additional bits are called parity bits. They allow detection or correction of the
errors.
The data bits along with the parity bits form a code word.
Even Parity − Even parity means the number of 1's in the given word including the parity
bit should be even (2,4,6,....).
Odd Parity − Odd parity means the number of 1's in the given word including the parity bit
should be odd (1,3,5,....).
For even parity, this bit is set to 1 or 0 such that the number of "1 bits" in the entire word is
even. See Fig. (a).
For odd parity, this bit is set to 1 or 0 such that the number of "1 bits" in the entire word is
odd. See Fig. (b).
How Does Error Detection Take Place?
Parity checking at the receiver can detect the presence of an error if the parity of the
receiver signal is different from the expected parity. That means, if it is known that the
parity of the transmitted signal is always going to be "even" and if the received signal has an
odd parity, then the receiver can conclude that the received signal is not correct.
If an error is detected, then the receiver will ignore the received byte and request for
retransmission of the same byte to the transmitter.
Simplicity − Binary codes use only two digits, i.e., 0 and 1 to represent information. It
simplifies the electronic circuit design and implementation.
Ease in Implementation − Binary codes use only two states namely, on and off. So,
their implementation is straightforward.
Ease of Storage − Binary codes are easy to store in digital memory devices like hard
disk, CD, DVD, pen drive, etc. They require compact storage at higher efficiency.
Easy and Fast Processing − Binary codes can be efficiently processed using digital
systems having an arithmetic and logic unit. They allow fast and error-free computing.
Easy Communication − Binary codes provide an efficient method of information
transmission at a very high speed. Various error detecting and correcting techniques
can be applied to binary codes that make the digital communication more efficient.
Easy Scalability − Binary codes provide easy scalability of a digital system. We can
increase the range of a digital system just by adding more bits in the code.
Compatibility − Binary codes are compatible with a wide range of digital devices and
systems.
Reliability − Binary codes are highly immune to noise and interference that provide
improved reliability in the digital system.