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

CODES

Uploaded by

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

CODES

Uploaded by

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

CODES

Coding
• The digital systems understands only 0’s and 1’s i.e. binary
language
• Generally information is in numeric, alphabetic or alphanumeric
form.
• Before processing the information by digital circuits information
should be converted into binary language.
• Coding is a process of conversion of information into binary
language.
• The codes in which the decimal digits 1 to 9 represented by
binary digits is called binary codes
• Number of codes are developed to simplify the communication
between machine and man.
• Generally information available in numerical, alphabetic or
alphanumeric form and it will not be understood by digital
circuits and digital systems so coding is needed.
Binary codes

• Binary codes are one of the important concepts in digital system


design.
• A binary code is a type of digital code consisting of two digits, 0
and 1.
• Binary codes act as the primary language in any digital
computing system.
• Binary codes can represent different types of information such
as numbers, letters, images, videos, etc.
• Binary codes form the primary language of a digital computing
system like a computer.

• All digital system can understand and manipulate information


expressed in binary language only. In the case of binary codes,
each digit is called a binary digit or bit.

• Binary codes represents information using 0 and 1.

• In a digital system, the binary codes are organized into segments


like bits or bytes. A bit is either a binary 0 or 1.

• When 8 bits are grouped together, then it is called a byte. Each


byte represents a piece of information in a digital system.
Types of Binary Codes

Binary codes can be classified into the following major types −

•Weighted Binary Codes


•Non-weighted Binary Codes
•Alphanumeric Code
•Binary Coded Decimal (BCD)
•Error Detecting Code
•Error Correction Code
Weighted Binary Codes
Each bit position has a specific weight associated with its positional
value.
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 × 22 + 1 × 21 + 1 × 20
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 20 = 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.
Non-Weighted Binary Codes

• In digital electronics, the type of digital or binary codes in which


each bit position does not have a specific weight associated with
it is known as a non-weighted binary code.

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

Excess-3 codes are obtained as follows −


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 symbols 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 −

•American Standard Code for Information Interchange (ASCII)


•Extended Binary Coded Decimal Interchange Code (EBCDIC)
•Five bit Baudot Code

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.
Advantages of BCD Codes

•BCD codes are very similar to the decimal system.


•We need to remember the binary equivalent of the decimal
numbers 0 to 9 only.

Disadvantages of BCD Codes

•The addition and subtraction of BCD codes follow different rules.


•BCD arithmetic is a little more complicated.
•BCD needs more number of bits than binary to represent the
decimal number. So, BCD is less efficient than binary.
Error Detecting Codes

• Error detecting codes are special types of binary codes used to


identify errors in digital communication and data storage.

• Error detecting codes add redundancy to the data that allows


receiver to identify if there is any error occurred.

• Common examples of error detecting codes include parity bit,


checksum, hamming code, etc.

• Error detecting codes are important to ensure integrity in data


transmission and storage. They help in improving the reliability of
the system.
What are Errors?

• An 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, i.e., a 0 bit may change to 1 or a 1 bit may change to 0.
• 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

• Error correcting codes are binary codes designed to correct


the errors occurred in a digital system during data
transmission or storage.

• Error correcting codes add some additional information to


the data to be transmitted or stored.

• 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.
How to Detect and Correct Errors?

To detect and correct the errors, additional bits are added to the data
bits at the time of transmission.
•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.
Parity Checking of Error Detection

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

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,....).
Use of Parity Bit

• The parity bit can be set to "0" or "1" depending on the type of
the parity required.
• 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.
Advantages of Binary Codes

•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.
Disadvantages of Binary Codes

•Binary codes are not human friendly. For human beings,


reading and interpreting binary codes can be a complex task.

•In some situations, binary codes have to be converted into


other number systems that adds extra computational
overhead to the system.

•Binary codes require higher transmission bandwidth in


communication channel.

•In binary codes, it is quite difficult to identify the errors. It


becomes more challenging in case of long binary sequences.
Applications of Binary Codes

Binary codes are widely used in various fields due to their high
efficiency in information representation.

•Digital Computers − Binary codes are primarily used in digital


computer to represent information and instructions.

•Digital Communication − Binary codes are also used for transmission


of data and information using digital channels.

•Digital Displays − Binary codes are also used to display numbers and
alphabets in digital systems.

•Barcode Systems − Binary codes are also used in barcode systems for
product identification and inventory management. In this system, bars
of different width and spaces between them represent binary digits
that can be interpreted by a scanner.
•Data Storage − Binary codes are used to store information in
digital devices like computer memory.

•Digital Control Systems − Binary codes are used to program a


digital control system. In a digital control system, binary codes
are used to represent different types of control signals and
instructions used for automation.

•Computer Graphics − Binary codes are also used in computer


graphics to represent colors, shapes, pixel values, and other
information.
ADDITIONAL SLIDES
Weighted Code:-
• In weighted code, each digit position have a
weight or value.
• The sum of all digits multiplied by a weight gives
the total amount being represented.
• We can express any decimal number in tens,
hundreds, thousands and so on.
Eg:- Decimal number 4327 can be written as
4327= 4000+300+20+7
In the power of 10, it becomes
4327= 4(10³)+3(10²)+2(10¹)+7(100)
BCD or 8421 is a type of weighted code where each
digit position is being assigned a specific weight.
BCD(binary coded decimal) or 8421 code:-
• It is composed of four bits representing the decimal digits 0 through
9.
• To represent any decimal number it uses 4 bit binary number.
• The 8421 indicates the binary weights of the four bits(2³,2²,2¹,20).
Decimal 8421(BCD)
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Packed BCD
The BCD numbers corresponding to decimal
numbers beyond 9 are called as packed BCD
Decimal (25)→ 0010 0101(Packed BCD)
Valid BCD Numbers
Decimal 8421(BCD)
10 0001 0000
11 0001 0001
12 0001 0010
13 0001 0011
14 0001 0100
15 0001 0101
16 0001 0110
17 0001 0111
18 0001 1000
19 0001 1001
20 0010 0000
320 0011 0010 0000
Binary coded decimal

0010 0000= 8bits=1byte


upper nibble lower nibble
nibble= 4 bits
Applications of BCD
• Used in digital voltmeter, electronic calculator
,digital computers.
Solve the following

• Convert following to BCD form


a) 47310 b) 31210 c) 25710 d) 11210

• Convert following BCD to their decimal equivalent


a) 10000110 b) 00110010.10010100

• Convert the following binary number numbers to their


BCD equivalent.
a) 1101.012 b) 11.0112
BCD Addition
Rules
• Add the given two bcd numbers
• If result is invalid bcd no. then add binary 6
into the result
• We get valid bcd result.
BCD addition
3 0011 8 1000
+4 0100 + 7 0111
------ ------- ------ ---------
7 0111 15 1111 invalid bcd
+ 0110
---------
1 0101 valid bcd
1 5
BCD Subtraction
4 0100 17 0001 0111
- 2 0010 - 8 0000 1000
borrow 1
------------ -----------------------------
0010 9 0000 1111
- 0110
-----------------------------
final answer 1001
BCD subtraction
555 0101 0101 0101
-234 0010 0011 0100
borrow 1 1
------------------------------------------
0011 0010 0001
BCD subtraction
898 1000 1001 1000
-259 0010 0101 1001
Borrow 11 1111 111
-----------------------------------------------
649 0110 0011 1111
- 0110
-----------------------------------------------
0110 0011 1001
BCD Addition
• 17 00010111
• 58 01011000
• ---------------------------
• 75 01101111
• 0110
• ------------------------
• 0111 0101

BCD Addition
• 569 0101 0110 1001
• 687 0110 1000 0111
• ------------------------------
• 1011 1111 0000
• 0110 0110 0110
• -----------------------------------
• 1 0010 0101 0110
Solve the following
Perform BCD operation of
• 17+58
• 569+687
• 28+16
• 37+65
• 57+26
• 45+33
• 147+284
• 65-12
• 45-23
• 35-20

You might also like