Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Binary Codes Notes

Uploaded by

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

Binary Codes Notes

Uploaded by

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

Study Material

Topic – BCD Codes

Key words Learning Objective: Conversion of Decimal Code to Binary Code,


BCD code Gray Code, BCD Code and Excess-3 Code
Excess -3 To apply code conversion from given
code number system into other specified
Gray code code such as Gray code, Excess-3
ASCII code code, and ASCII code.

Key Concept Map


Questions
Q1. Define
weighted and
non-weighted
code.
Q2. Do you
know Codes Key Definitions
theGray code When numbers, letters or words are
is used for BCD code: In this code each decimal digit is
represented by a specific group of
error symbols, it is said that the number, represented by a 4-bit binary number.
correction? letter, or word is being encoded. The Excess-3 Code: The Excess-3 code words are
group of symbols is called as a code. derived from the 8421 BCD code words by
The digital data is represented, stored, adding (0011)2 or (3)10 to each code word in
and transmitted as group of binary 8421.
bits. This group is also called
as binary code. The binary code is Gray code: Itis defined as an ordering of the
represented by the number aswell binary number system such that each
as alphanumeric letter. incremental value can only differ by one bit.
Numeric codes are used to represent
numbers. ASCII Code: ASCII Code (American
Alphanumeric codes are used to Standard Code for Information Interchange) is
represent characters: Alphabetic a 7-bit code and can represent 27 = 128
letters and numerals. possible characters and symbols.

Application of 1’s complement Link to YouTube/ OER/ video


method
https://nptel.ac.in/courses/108/105/108105132
 Computerapplications /
 Digital communication click on lecture 28
 Analog to digital converters
 Error correction in digital https://www.tutorialspoint.com/computer_logi
communication cal_organization/binary_codes.htm#:~:text=Er
 Rotary and Optical encoders ror%20Correcting%20Codes-
,Weighted%20Codes,a%20group%20of%20fo
ur%20bits.
Classification of binary codes

The codes are broadly categorized into following four categories.

 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.

 American Standard Code for Information Interchange (ASCII).


 Extended Binary Coded Decimal Interchange Code (EBCDIC).
 Hollerith Code.
Reflective Code

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.

Error detection and Correcting 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.

BCD(Binary coded decimal) Codes


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.
The positional weights associated to the binary bits in BCD code are 8-4-2-1 with 1
corresponding to LSB and 8 corresponding to MSB. These weights are actually 2³ 2² 2¹
2⁰ which are same as those used in normal binary system.
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.

Example: convert (35)10 into BCD


3 0011
5 0101
So (35)10 = (00110101)BCD

Binary to BCD Conversion

Steps
 Step 1 -- Convert the binary number to decimal.
 Step 2 -- Convert decimal number to BCD.
Example − convert (11101)2 to BCD.

Step 1 − Convert to Decimal

Binary Number − 111012


Calculating Decimal Equivalent −

Step Binary Number Decimal Number

Step 1 111012 ((1 × 24) + (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20))10

Step 2 111012 (16 + 8 + 4 + 0 + 1)10

Step 3 111012 2910

Binary Number − 111012 = Decimal Number − 2910

Step 2 − Convert to BCD

Decimal Number − 2910


Calculating BCD Equivalent. Convert each digit into groups of four binary digits equivalent.

Step Decimal Number Conversion

Step 1 2910 00102 10012

Step 2 2910 00101001BCD

Result
(11101)2 = (00101001)BCD

BCD to Binary Conversion

Steps
 Step 1 -- Convert the BCD number to decimal.
 Step 2 -- Convert decimal to binary.
Example − convert (00101001)BCD to Binary.

Step 1 - Convert to BCD

BCD Number − (00101001)BCD

Step BCD Number Conversion

Step 1 (00101001)BCD 00102 10012

Step 2 (00101001)BCD 210 910

Step 3 (00101001)BCD 2910

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 2 - Convert to Binary

Used long division method for decimal to binary conversion.


Decimal Number − 2910
Calculating Binary Equivalent −

Step Operation Result Remainder

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.

BCD to Excess-3 Conversion

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.

Step 1 − Convert to decimal

(0110)BCD = 610

Step 2 − Add 3 to decimal

(6)10 + (3)10 = (9)10

Step 3 − Convert to Excess-3

(9)10 = (1001)2
Result
(0110)BCD = (1001)XS-3

Excess-3 to BCD Conversion

Example − convert (10011010)XS-3 to BCD.

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.

You might also like