Unit 2.lesson 4 Numeric and Alphanumeric Codes
Unit 2.lesson 4 Numeric and Alphanumeric Codes
FPPT.com
Lesson 4
Numeric and Alphanumeric Codes
FPPT.com
Numeric and Alphanumeric Codes
• Earlier computers - used only for calculations.
• Modern computers - not just used for numeric
representations, they are also used to
represent information such as names,
addresses, item descriptions etc.
• Information is represented using letters and
symbols.
Numeric and Alphanumeric Codes
• Computer - digital system that can only
deal with 1’s and 0’s.
• Computer deal with letters and symbols
using alphanumeric codes.
• Alphanumeric codes, also called
character codes, are used to deal with
letters and symbols.
Numeric and Alphanumeric Codes
• These are binary codes used to represent
alphanumeric data.
• These codes are used to interface input-
output devices such as keyboards,
monitors, printers etc. with computer.
Numeric and Alphanumeric Codes
• When numbers, letters or words are represented by
a specific group of symbols in coding, it is said that
the number, letter or word is being encoded.
• Code - the group of symbols.
• digital data is represented, stored and transmitted as
group of binary bits also called binary code.
• Binary Code - represented by the number as well
as alphanumeric letter.
Advantages of Binary Codes
• Suitable for the computer applications.
• Suitable for the digital communications.
• Make the analysis and designing of digital
circuits if we use the binary codes.
• Implementation is easier with only 0 & 1
being used.
Classification of Binary Codes
The codes are broadly categorized into
following four (4).
• Weighted Codes/ Non-Weighted Codes
• Binary Coded Decimal Code
• Alphanumeric Codes
• Error Detecting Codes/ Error Correcting
Codes
Weighted and Non-Weighted
Codes
FPPT.com
Weighted Binary 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.
• Each decimal digit is represented by a group of
four bits.
Weighted Binary Codes
Non-Weighted Binary Codes
• Positional weights are not assigned for
non-weighted binary codes.
• The examples of non-weighted codes are
– Excess-3 code and
– Gray code.
Excess-3 Codes
• Excess-3 code - also called as XS-3 code.
• It is a 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.
• Excess-3 codes are obtained as follows:
Excess-3 Codes
Gray Codes
• A non-weighted nor arithmetic code.
• No specific weights assigned to the bit position.
• 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.
Gray Codes
BCD-XS-3, Gray Codes Comparison
BCD Excess-3
Decimal (8 4 2 1) BCD + 0011 Gray Code
0 0 0 0 0 0 0 1 1 0 0 0 0
1 0 0 0 1 0 1 0 0 0 0 0 1
2 0 0 1 0 0 1 0 1 0 0 1 1
3 0 0 1 1 0 1 1 0 0 01 0
4 0 1 0 0 01 1 1 0 1 1 0
5 0 1 0 1 1 0 0 0 0 1 1 1
6 0 1 1 0 1 0 0 1 0 1 0 1
7 0 1 1 1 1 0 1 0 0 1 0 0
8 1 0 0 0 1 0 1 1 1 10 0
9 1 0 01 1 1 0 0 1 1 0 1
Gray Code Application
• Gray code is popularly used in the shaft position
encoders.
• A shaft position encoder produces a code word
which represents the angular position of the shaft.
Binary Coded Decimal (BCD)
code
FPPT.com
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, sixteen numbers
(0000 to 1111) can be represented.
Binary Coded Decimal (BCD) Code
• It is very similar to decimal system.
• It applies the binary equivalent of decimal
numbers 0 to 9 only.
• Only the first ten combination of four bits is
used in BCD code (0000 to 1001).
• The remaining six code combinations are
invalid in BCD
– i.e. 1010 to 1111.
Binary Coded Decimal (BCD) Code
Disadvantages of Binary Coded Decimal (BCD)
• 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.
• BCD is less efficient than binary.
Alphanumeric Codes
FPPT.com
Alphanumeric Codes
Alphanumeric Codes
• A binary digit or bit can represent only two
symbols as it has only two states '0' or '1’.
• Not enough for communication between two
computers because many more symbols are
needed 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
• 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.
Alphanumeric Codes
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).
• Five bit Baudot Code.
Alphanumeric Codes - ASCII
• 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/ Error
Correcting Codes
FPPT.com
Error Codes
• There are binary code techniques
available to detect and correct data during
data transmission.
Error Codes
• 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.
• Error-detecting codes which are additional
data added to a given digital message to
detect if an error occurred during
transmission of the message are used.
• A simple example of error-detecting code is
parity check.
Error Correcting Codes
• Along with error-detecting code, some data
can also be passed to figure out the original
message from the received corrupt message.
• This type of code is called an error-correcting
code.
• Error-correcting codes also deploy the same
strategy as error-detecting codes but
additionally, such codes also detect the exact
location of the corrupt bit.
Error Correcting Codes
• 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.
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.
Parity Checking of Error Detection
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 and 1 depending on
the type of the parity required.
• For even parity, this bit is set to 1 or 0 such that
the no. of "1 bits" in the entire word is even. Fig.
(a).
• For odd parity, this
bit is set to 1 or 0
such that the no. of
"1 bits" in the entire
word is odd. Fig.
(b).
How Error Detection Takes 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.
• 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.
How Error Detection Takes Place
• If an error is detected, then the receiver will
ignore the received byte and request for
retransmission of the same byte to the
transmitter.
Error Codes
• 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.
Codes Conversion
FPPT.com
Codes Conversion
Among the methods or techniques which can be
used to convert code from one format to another
are the following:
• Binary to BCD Conversion
• BCD to Binary Conversion
• BCD to Excess-3
• Excess-3 to BCD
Binary to BCD Conversion
Codes Conversion
FPPT.com
Binary to BCD Conversion
Steps
1. Convert the binary number to decimal.
2. Convert decimal number to BCD.
Example −
• convert (11101)2 to BCD.
Binary to BCD Conversion
Step 1 − Convert to Decimal
1. Binary Number − 111012
2. Calculating Decimal Equivalent −
Step 1 Binary Number Decimal Number
1 111012 1*24 + 1*23 + 1*22 + 0*21 +1*20
2 16 + 8 + 4 + 0 + 1
3 292
Result
(11101)2 = (00101001)BCD
BCD to Binary Conversion
Codes Conversion
FPPT.com
BCD to Binary Conversion
Steps
1. Convert the BCD number to decimal.
2. Convert decimal to binary.
Example −
convert (10011000)BCD to Binary.
BCD to Binary Conversion
Step 1 − Convert to Binary
1. Given Binary Number − (10011000)BCD
2. Calculating Decimal Equivalent. Convert each four digit
into a group and get decimal equivalent for each group.
Step 1 Decimal Number Conversion
1 (10011000)BCD 10012 10002
2 910 810
3 9810
Result
(10011000)BCD = 9810
BCD to Binary Conversion
Step 2 − Convert to Binary
1. Decimal Number − 9810
2. Follow steps for decimal to binary conversion.
Step Operation Quotient Remainder
1 98/2 49 0
2 49/2 24 1
3 24/2 12 0
4 12/2 6 0
5 6/2 3 0
6 3/2 1 1
7 1/2 0 1
BCD to Binary Conversion
Step 2 − Convert to Binary
3. The remainders from the calculation table
(shown in the previous slide) 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).
4. Decimal Number − 9810 = Binary Number −
11000102
Result: (10011000)BCD = (1100010)2
BCD to EXCESS-3 Conversion
Codes Conversion
FPPT.com
BCD to Excess-3 Conversion
Steps
1. Convert BCD to decimal.
2. Add (3)10 to the decimal value
3. Convert into binary to get excess-3 code.
or
1. Convert BCD to decimal.
2. Convert decimal value to binary.
3. Add (0011)2 to the binary value to get excess-3
code.
BCD to Excess-3 Conversion
Example −
convert (1001)BCD to Excess-3.
1. Convert to decimal
(1001)BCD = 910
2. Add 3 to decimal
(9)10 + (3)10 = (12)10
3. Convert to Excess-3
(12)10 = (1100)2
Result
(1001)BCD = (1100)XS-3
EXCESS-3 to BCD Conversion
Codes Conversion
FPPT.com
Excess-3 to BCD Conversion
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.
Excess-3 to BCD Conversion
convert (10011010)XS-3 to BCD.
Given XS-3 number = 1 0 0 1 1 0 1 0
Subtract (0011)2 =1001 0111
--------------------
BCD = 0 1 1 0 0 1 1 1
Result
(10011010)XS-3 = (01100111)BCD
Excess-3 to BCD Conversion
convert (10011010)XS-3 to BCD.
Given XS-3 number = 1 0 0 1 1 0 1 0
Subtract (0011)2 =1001 0111
--------------------
BCD = 0 1 1 0 0 1 1 1
Result
(10011010)XS-3 = (01100111)BCD
Exercises are provided for
Laboratory activity
FPPT.com