Binary Codes - Chapter 3
Binary Codes - Chapter 3
• The BCD codes for six decimal numbers from 10 to 15 are given in Table below
These six codes are called forbidden codes and the group of these
codes is called the forbidden group in BCD code. Weights of the
numbers can be represented as negative representatives as in 8, 4,
2, 1 code. The complements of the numbers are taken for negative
representation. Thus, this is self-complementing code. Each bit is
individually complemented (by changing 1’s to 0’s and 0’s to 1’s)
and this new code word represents the complement of the digit to
which the original code word corresponds. For example, 0101
represents 3 in the 8, 4, 2, 1 code, and 1010 represents 6 in this
code. It is a weighted and self-complementing code.
Binary Coded Decimal (BCD) or 8421 Code
Step I. Write 0 and 1 Step II. Write these 4 codes and again
and put a mirror, we put a mirror. The code will look in the
first see 1 and then 0. order 10, 11, 01 and 00. Then place 0’s
Place 0’s above mirror above mirror and 1’s below mirror.
and 1’s below mirror Proceeding intactively in the same
We have got gray code manner. We can form Gray code for any
for decimal digits 0 decimal digit.
through 4.
Binary to Gray conversion
• (1) Place a leading zero before the most significant bit (MSB) in the binary
number.
• (2) Exclusive-OR (EXOR) adjacent bits together starting from the left of this
number will result in the Gray code equivalent of the binary number.
• Exclusive–OR– If the two bits EX–OR’d are identical, the result is 0; if the two
bits differ, the result is 1.
• Conversion of a Binary Number into Gray Code. Any binary number can be converted
into equivalent Gray code by the following steps:
• (i) the MSB of the Gray code is the same as the MSB of the binary number;
• (ii) the second bit next to the MSB of the Gray code equals the Ex-OR of the MSB and
second bit of the binary number; it will be 0 if there are same binary bits or it will be 1
for different binary bits;
• (iii) the third bit for Gray code equals the exclusive-OR of the second and third bits of
the binary number, and similarly all the next lower order bits follow the same
mechanism.
Conversion of Gray Code into a Binary Number
• Any Gray code can be converted into an equivalent binary number by the
following steps:
• (i) the MSB of the binary number is the same as the MSB of the Gray code;
• (ii) the second bit next to the MSB of the binary number equals the Ex-OR of the
MSB of the binary number and second bit of the Gray code; it will be 0 if there
are same binary bits or it will be 1 for different binary bits;
• (iii) the third bit for the binary number equals the exclusive-OR of the second bit
of the binary number and third bit of the Gray code, and similarly all the next
lower order bits follow the same mechanism.
Binary-to-Gray Conversion
• There are two methods of converting Gray code to Binary code. The rules for
converting from any binary number to its equivalent Gray code number are as
follows:
• Thus the resulting values are 4 8, 4 5, 4 C, 4 C and 4 F. Now locate these hexadecimal
values in Table 2-9 and determine the character represented by each. The results are
• “H E L L O”
• The ASCII code is used extensively to exchange information between the computer and
its peripheral devices.
ASCII Applications
• They are mainly used to give instructions to microcomputers
• It is used for interfacing devices
• It is used in the transfer of information from keyboards to computer displays and
printers
Assignment
• Represent the decimal number
• (a) 27 (b) 396 (c) 4096 in (i) binary form (ii) In ASCII Code (iii) Gray code (iv)
Excess 3 Codes.
• The following is a message encoded in ASCII code.
• 1001000 1000101 1001100 1001100 1001111
• What is the message?
Solution: Given the message encoded in the ASCII code:
1001000 1000101 1001100 1001100 1001111 1001000 Corresponds to ‘H’
We know that to read the message we have to convert the given 1000101 Corresponds to ‘E’
data string into the corresponding characters by using the 1001100 Corresponds to ‘L’
ASCII code Table. From this table we find that, 1001100 Corresponds to ‘L’
Therefore the given data string represents the message 1001111 Corresponds to ‘O’
“HELLO”
Extended Binary Coded Decimal Interchange Code
(EBCDIC)
• The second commonly used alphanumeric code is EBCDIC (Extended Binary
Coded Decimal Interchange Code), pronounced as “eb-si-dik”. This is an 8-bit
code developed by IBM mainly used in larger computers. EBCDIC code finds its
application in all IBM mainframe computer peripherals and operating systems. A
single byte in EBCDIC is divided into two 4-bit groups called nibbles. The first 4-
bit group represents the category of the character and is called the “zone”, while
the second 4-bit group identifies the specific character and is called the “digit”.
EBCDIC can correspond to 256 characters. EBCDIC does not provide any
advantage over ASCII code except that it is easier to enter data into larger
machines.
Extended Binary Coded Decimal Interchange Code
(EBCDIC)
• The EBCDIC code for first few decimal number is provided in Table 2.13.
The Excess Three (Xs-3) Code
• The Excess-3 code, also called XS-3, is a non-weighted BCD code. This code
derives its name from the fact that each binary code word is the corresponding
8421 code word plus 011(3). It is a sequential code and, therefore, can be used for
arithmetic operations. It is self-complementing code. Therefore, subtraction by the
method of complement addition is more direct in XS-3 code than that in 8421
code. The XS-3 code has six invalid states 0000 0001, 0010, 1101, 1110 and 1111.
• Excess-3 Codes
• The excess-3 code is obtained by adding (0011)2 or (3)10 to the desired 8421
code. A given decimal number is converted to its excess-3 code by adding “3” to
each decimal digit in the given number and replacing each digit of the newly
found decimal number by its 4-bit binary equivalent. The addition of “3” to a
binary digit in 8421 coded form produces a carry and is not taken forward. The
result of addition should be taken as a single entity and subsequently replaced with
its excess-3 code equivalent.
Excess-3 (XS-3) Code
• Excess-3 code is an example of unweighted code (the positional weights are not
assigned) and it is obtained by adding 3 and then converting it to a binary format.
For instance to find excess-3 representation of the decimal number 4, first 3 is
added to 4 to get 7 and then binary equivalent of 7 i.e. 0111 forms the excess-3
equivalent of 4. The table represents excess-3 equivalent of decimal numbers (0-
9).
Excess-3 code is also known as self complimenting code
or reflective code, as 1′s compliment of any number (0-9)
is available within these 10 numbers. For example 1′s
complement of 9 (1100) is 0011.
The XS-3 code words are derived from the 8421 BCD
code words adding (0011)2 or (3)10 to each code word in
8421
Excess-3 (XS-3) Code
Addition of two numbers in Excess-3 Code
Example-: To obtain an excess-3 equivalent, binary 3 needs
• 0101 (2) to be subtracted from the result as follows:
1101 (10)
• + 1000 (5)
- 0011 (3)
• --------- --------
• 1101 (10) 1010 (7)
• The result 1101 is in excess-6.
Excess-3 (XS-3) Code
• The excess-3 code is also called XS-3 code. It is non-weighted code used to
express decimal numbers. The difficulties encountered during arithmetic
operations are overcome by using excess-3 codes. This makes the excess-3 codes
significant for arithmetic operations.
• Find the Excess-3 code for the following:
(i) 24 Solution:
(i) The decimal number 24 is represented in BCD code with
(ii) (156.75)10 the individual binary equivalents. To this binary number,
(iii) 1000 1100 1010 0011 is added which results in the excess-3 code for 2410 .
2 4
0010 0100
Answer: 0101 011
The excess-3 code can also be obtained by directly adding 3
to 2 and 4. This adds up to 5 and 7. It is written in the binary
code.
Excess-3 (XS-3) Code
• (ii) (156.75)10
• The integer part is first converted into excess binary code. The excess-3 code for
151 is 0100 1011 0100. The fractional part .75 is converted by replacing 7 and 5
with the 4-bit binary equivalents of 10 and 8, respectively. The excess-3 code for
(.75)10 is (.10101000).
• Answer: (151.75)10 in Excess-3 code is 010010110100.10101000.
• (iii) The excess-3 code for the given binary number is obtained by subtracting
0011 from each 4-bit group.
• 1000 1100 1010
• 5 9 7
• The binary number thus obtained after subtraction is 0011 0100 01 Excess-3 code
is 010110010111 and its binary equivalent is 26410 .
Error Detection and Correction
• As a matter of fact, the movement of binary data and codes from one location to
another is the most frequent operation performed in digital electronic systems. For
example:
1. The transmission of digitized voice over a mobile phone
2. The storage of data in and retrieval of data from external memory devices such as
magnetic tape and disk
3. The transmission of information from a computer to a remote user terminal or
another computer over telephone lines
• Whenever information is transmitted from one electronic system (say transmitter)
to another system (say receiver), there is a possibility that errors can occur such
that the receiver does not receive the identical information that was sent by the
transmitter. The major reason for any transmission errors is electrical noise. The
noise consists of spurious fluctuations in voltage or current that are
Parity Method For Error Detection
• Error is said to be any unwanted change in the output information as compared to
the input information. In Analog systems, there is a possibility of some undesired
signals being received at the receiver. These undesired signals are referred as
noise. This causes error during signal transmission.
• On the other hand, in digital systems since the information is transferred as bits,
errors occur due to interchanging of bits. Error is produced when a bit changes
from “0” to “1” or “1” to “0” while data is transferred from one computer to
another. The process of error occurrence is as shown in Figure below. The error
caused might even corrupt the data transferred. Therefore, it is essential to check if
any error is caused during the process.
Parity Method For Error Detection
• Methods have to be evolved to keep the error in check so that once an error is
detected it has to be notified. To overcome this problem, digital devices use the
error detecting code and its correction. The error detection code is added to the
input data and if there is an error that had occurred. Many digital electronic
systems employ some method for detection (and correction) of errors. One of the
simplest and most widely used methods for error detection is the Parity Method or
the Parity code
Parity Method For Error Detection
• Parity Bit
• Strictly speaking, a Parity bit is an extra bit that is attached to a code group that is being
transmitted from one location to another. The parity bit is made either 0 or 1, depending
on the number of 1s that are contained in the code group. Two different methods are used
for attaching an extra bit. These are discussed below.
• The Even Parity Method
• In this method, the value of the parity bit is chosen so that the total number of 1s in the
code group (including the parity bit) is an even number. For example, suppose that the
code group is 1000101. This is the ASCII character “E”. The code group has three 1s.
Therefore, we will add a parity bit of 1 to make the total number of 1s an even number.
The new code group, including the parity bit, thus becomes 11000101.
• The Odd Parity Method
• In this method, the value of the parity bit is chosen so that the total number of 1s in the
code group (including the parity bit) is an odd number. For example, suppose the code
group is 1000101. The code group has three 1s. Therefore we will add a parity bit of o to
keep the total number of 1s an odd number. The new code group including the party bit
becomes 01000101.
Even and Odd Parity
• Examples for even and odd parity
Thus, the data can be corrected by setting the
parity bit. The error is identified at the
receiver by noting if there exists any change
in the parity other than the expected data. If
the receiver signal or data is expected to be of
odd parity but an even parity occurs then we
can confirm for an error. The receiver does
not take into account this byte and
retransmits the same to the transmitter.
Even and Odd Parity
• What parity do the following words have
(i) 11001101
(ii) 10110100
• Assign the proper even parity bit to the following code groups:
(a) 1010 (b) 111000 (c) 101101
• Computers often communicate with other remote computers over the telephone
lines-this is how the communication takes place over the internet. When one
computer is transmitting a message to another, the information is usually encoded
in ASCII. What actual bit strings would a computer transmit to send the message
TECHNOLOGY using ASCII with even parity.
Other error detection and correction codes
Error detection codes
1. Checksum
2.Block parity
3.Repetion
Cyclic redundant Check