Binary Codes Notes
Binary Codes Notes
Weighted Codes
Non-Weighted Codes
Reflective Codes
Sequential Codes
Alphanumeric Codes
Error Detecting and correcting 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. Several systems of the codes are
used to express the decimal digits 0 through 9. In these codes each decimal digit is represented
by a group of four bits. The examples are Binary and BCD code.
Non-Weighted Codes
In this type of binary codes, the positional weights are not assigned. The examples of non-
weighted codes are Excess-3 code and Gray code.
Alphanumeric codes
The 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. An alphanumeric code should at least represent 10
digits and 26 letters of alphabet i.e. total 36 items. The following three alphanumeric codes
are very commonly used for the data representation.
It can be observed that in the 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 reflexive codes.
Sequential Codes
Sequential codes are the codes in which 2 subsequent numbers in binary representation differ
by only one digit. The 8421 and Excess-3 codes are examples of sequential codes. 2421 and
5211 codes do not come under sequential codes.
When digital data is transmitted from one system to another system an error my occur due to
noise. To maintain the data integrity between transmitter and receiver ,extra bit or more than
one bit are added in the date. These extra bits allow detection and sometimes correction of
error in the data. The data along with the extra bits forms the code.
Codes which allow only detection of errors are called error correction codes and codes which
allow detection and correction are called error detection and correction codes.
Steps
Step 1 -- Convert the binary number to decimal.
Step 2 -- Convert decimal number to BCD.
Example − convert (11101)2 to BCD.
Result
(11101)2 = (00101001)BCD
Steps
Step 1 -- Convert the BCD number to decimal.
Step 2 -- Convert decimal to binary.
Example − convert (00101001)BCD to Binary.
Calculating Decimal Equivalent. Convert each four digits into a group and get decimal
equivalent for each group.
BCD Number − (00101001)BCD = Decimal Number − 2910
Step 29 / 2 14 1
1
Step 14 / 2 7 0
2
Step 7/2 3 1
3
Step 3/2 1 1
4
Step 1/2 0 1
5
The remainders have to be arranged in the reverse order so that the first remainder becomes
the least significant digit (LSD) and the last remainder becomes the most significant digit
(MSD).
Decimal Number − 2910 = Binary Number − 111012
Result
(00101001)BCD = (11101)2
Advantages of BCD Codes
It is similar to decimal system.
We need to remember binary equivalent of decimal numbers 0 to 9 only.
Disadvantages of BCD Codes
The addition and subtraction of BCD have different rules.
The BCD arithmetic is little more complicated.
BCD needs more number of bits than binary to represent the decimal number. So
BCD is less efficient than binary.
Excess-3 code
The Excess-3 code is also called as XS-3 code. It is non-weighted code used to express
decimal numbers.
The Excess-3 code words are derived from the 8421 BCD code words by adding (0011)2 or
(3)10 to each code word in 8421
It is a sequential code because any code word can be obtained by adding binary 1 to its
previous code.
In excess-3 code we get 9’s complement by just complementing each bit hence it is called
self -complimenting code. The excess-3 codes are obtained as follows −
For example, to convert 15 to an excess-3 code, first 3 to be added to each digit as shown
below.
Steps
Step 1 -- Convert BCD to decimal.
Step 2 -- Add (3)10 to this decimal number.
Step 3 -- Convert into binary to get excess-3 code.
Example − convert (0110)BCD to Excess-3.
(0110)BCD = 610
(9)10 = (1001)2
Result
(0110)BCD = (1001)XS-3
Steps
Step 1 -- Subtract (0011)2 from each 4 bit of excess-3 digit to obtain the corresponding
BCD code.
Example − convert (10011010)XS-3 to BCD.
Given XS-3 number 1 0 0 1 1 0 1 0
Subtract (0011)2- 0 0 1 1 0 0 1 1
11 111
--------------------
BCD = 0 1 1 0 0 1 1 1
Result
(10011010)XS-3 = (01100111)BCD
Gray code
It is also known as Cyclic Code, Reflected Binary Code (RBC), Reflected Binary (RB) or
Grey code – is defined as an ordering of the binary number system such that each
incremental value can only differ by one bit.
In gray code, while traversing from one step to another step only one bit in the code group
changes. That is to say that two adjacent code numbers differ from each other by only one
bit.
Gray code is the most popular of the unit distance codes, but it is not suitable for arithmetic
operations.
Gray code has some applications in analog to digital converters, as well as being used for
error correction in digital communication. Gray codes are used in rotary and optical
encoders.
Gray code to binary code conversion
Steps:
1. To convert Gray code to binary, bring down the most significant digit of the given Gray
code number, because, the first digit or the most significant digit of the Gray code number is
same as the binary number.
2. To obtain the successive second binary bit, perform the EX-OR operation between the
first bit or most significant digit of binary to the second bit of the given Gray code.
3. To obtain the successive third binary bit, perform the EX-OR operation between the
second bit or most significant digit of binary to the third MSD (most significant digit) of
Gray code and so on for the next successive binary bits conversion to find the equivalent
Example:
Binary code of (01101)Gray
Binary to Gray code conversion
Steps:
1.To convert binary to Gray code, bring down the most significant digit of the given binary
number, because, the first digit or most significant digit of the Gray code number is same as
the binary number.
2. To obtain the successive Gray coded bits to produce the equivalent Gray coded number
for the given binary, perform EX-OR operation between the first bit or the most significant
digit of binary to the second one and write down the result next to the first bit of Gray code.
3.Repeat the step 2 until all binary bits hae been EX-ORed with their previous ones.
Example:
Table shows the 4 bit binary code and 4 bit Gray code for the decimals numbers from 0 to
15.
ASCII Code
ASCII Code(American Standard Code for Information Interchange) is a 7-bit code and can
represent 27 = 128 possible characters,
This code is sufficient to represent all the standard keyboard characters as well as control
functions such as RETURN etc,
Table shows the partial listing of ASCII Code.
For example, ASCII Code for K is (1001011)2.
Key Take away
Classification of codes
BCD and Binary Codes are Weighted Codes
Gray and Excess-3 Codes are Non weighted codes
ASCII is Alphanumeric Code.
Conversion from one code to another.