0% found this document useful (0 votes)
18 views

Binary Codes

Uploaded by

mvpk14486
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Binary Codes

Uploaded by

mvpk14486
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

BINARY CODES

Contents:
• Definition
• Classification
• Examples
BINARY CODES:

•When numbers, alphabets or words are represented by a specific


group of symbols i.e., they are encoded
•The group of symbols used to encode them are called codes. The
digital data is represented, stored and transmitted as groups of
binary digits (bits)
•Group of bits  binary code  numeric and alphanumeric code
Classification of binary codes:

The codes are broadly categorized into following four categories.

1. Weighted Codes
2. Non-Weighted Codes
3. Binary Coded Decimal Code
4. Alphanumeric Codes
Weighted Codes:

• Weighted binary codes are those binary codes with


positional weight.
• 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.
Non-weighted codes:

• Non-weighted codes are not assigned with any weight


to each digit position, i.e., each digit position within
the number is not assigned fixed value

• Excess-3 and gray codes are the non-weighted codes


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 adding (0011)2 or (3)10 to each
code word in 8421.
• The excess-3 codes are obtained as follows
Example
Gray Code:
• It is the non-weighted code and it is not arithmetic
codes. That means there are no specific weights assigned
to the bit position.
• It has a very special feature that, only one bit will
change each time the decimal number is incremented.
• As only one bit changes at a time, the gray code is
called as a unit distance code.
• The gray code is a cyclic code. Gray code cannot be
used for arithmetic operation.
Binary to Gray conversion :
1.The Most Significant Bit (MSB) of the gray code is always equal
to the MSB of the given binary code.
2.Other bits of the output gray code can be obtained by XORing
binary code bit at that index and previous index.
Gray to binary conversion:

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:

• A binary digit or bit can represent only two symbols as it has


only two states '0' or '1‘.
• The alphanumeric codes are the codes that represent numbers
and alphabetic characters
• 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.
1. American Standard Code for Information Interchange (ASCII).
2. Extended Binary Coded Decimal Interchange Code (EBCDIC).
3. Five bit Baudot Code.
• ASCII code is a 7-bit code whereas EBCDIC is an 8-bit code.
ASCII code is more commonly used worldwide while EBCDIC
is used primarily in large IBM computers.
Error-Detecting codes:
What is Error?
• Error is a condition when the output information does not match
with the input information.
• During transmission, digital signals suffer from noise that can
introduce errors in the binary bits travelling from one system to
other.
• That means a 0 bit may change to 1 or a 1 bit may change to 0.
Error-Detecting codes:
• 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.
1. Parity Check:

It is the simplest technique for detecting and correcting errors. The


MSB of an 8-bits word is used as the parity bit and the remaining 7
bits are used as data or message bits. The parity of 8-bits transmitted
word can be either even parity or odd parity.
While creating a frame, the sender counts the number of 1s in it and
adds the parity bit in following way:

•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

Example: Consider 126 whose binary value is 1 1 1 1 1 0 0


Even Parity:
Parity Bit Data Bits
1 1 1 1 1 1 0 0

Odd Parity:

Parity Bit Data Bits


0 1 1 1 1 1 0 0
Example: Consider 114 whose binary value is 1 1 1 0 0 1 0
Even Parity:
Parity Bit Data Bits
0 1 1 1 0 0 1 0

Odd Parity:
Parity Bit Data Bits
1 1 1 1 0 0 1 0
Checksum:

In this error detection scheme, the following procedure is applied

• Data is divided into fixed sized frames or segments.


• The sender adds the segments using 1’s complement arithmetic to
get the sum. It then complements the sum to get the checksum
and sends it along with the data frames.
• The receiver adds the incoming segments along with the
checksum using 1’s complement arithmetic to get the sum and
then complements it.
• If the result is zero, the received frames are accepted; otherwise
they are discarded.
For example:

Let us consider, the data to be sent is


1010100100111001
Sender side processing
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
F1: 1 0 1 0 1 0 0 1
F2: 0 0 1 1 1 0 0 1
-------------------
F1 + F2= 1 1 1 0 0 0 1 0
-------------------
Step3: Perform 1’s complement
Resultant = 0 0 0 1 1 1 0 1 Checksum
Now the sender sends the data to the receiver in the following
format:

Data Bits + 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)

• CRC or Cyclic Redundancy Check is a method of detecting


accidental changes/errors in the communication channel.

CRC uses Generator Polynomial which is available on both sender


and receiver side.

An example generator polynomial is of the form like x3 + x + 1.


This generator polynomial represents key 1011.

Another example is x2 + 1 that represents key 101.


n : Number of bits in data to be sent from sender side.
k : Number of bits in the key obtained from generator polynomial .
Sender Side (Generation of Encoded Data from Data and
Generator Polynomial (or Key)):

• 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):

Perform modulo-2 division again and if the remainder is 0, then there


are no errors.

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):

Data word to be sent - 100100


Key - 1101 [ Or generator polynomial x3 + x2 + 1]
Sender Side:

Therefore, the remainder is


001 and hence the encoded
data sent is 100100001.
Receiver Side:
Code word received at the receiver side 100100001

Therefore, the remainder is all


zeros. Hence, the data received has
no error.
Example 2: (Error in transmission)
Data word to be sent – 100100 Key - 1101

Sender Side:

Therefore, the remainder is


001 and hence the code word
sent is 100100001.
Receiver Side:
Let there be an error in transmission media Code word received at the
receiver side – 100000001

Since the remainder is not all


zeroes, the error is detected at
the receiver side.

You might also like