Binary Codes
• Electronic digital systems use signals that have two
distinct values (0 and 1) and circuit elements that
have two stable states (ON and OFF).
• Digital systems represent and manipulate binary
numbers, as well as other discrete elements of
information using binary codes.
• A binary code is just an assignment of numeric
values to bit patterns. Binary codes merely change
the symbols, but not the meaning of the elements of
information that they represent.
– To represent a group of 2n distinct elements in a
binary code requires a minimum of n bits.
– There is no maximum number of bits that may be
used for a binary code.
Binary Codes
Binary Codes for Decimal Digits
BCD
2421
Excess 3
8, 4, -2, -1
Gray Code
Character Code
ASCII
Error Detection Codes
Even parity
Odd Parity
Binary Codes for Decimal Numbers
Binary Codes for Decimal
Numbers
The usual interpretation of a binary number is as
defined according to the definition of a number in
in base-2 system.
There are, however, alternate methods used to
encode numeric data into binary bit patterns.
Note: All upcoming tables present binary codes
and not binary numbers.
1. Binary Coded Decimal
(BCD)
Refers to Binary Coded Decimal
BCD number is just a natural binary
encoding of the decimal digits from 0
to 9 on four bits.
Therefore a string of bits is grouped
into groups of four bits, and
interpreted as a string of decimal
digits.
Takes more space to represent
binary numbers but its easily
understandable
Similar to Hex, but it stops at 9.
Hence, 6 combinations are
wasted.
E.g. 1510 = 11112 in binary and
1. Binary Coded Decimal
(BCD)
Binary-Coded Decimal is a weighted code because
each decimal digit can be obtained from its code word
by assigning a fixed weight to each code-word bit.
BCD is also called as the 8421 code, owing to the
weights of the BCD bits
Two BCD digits are added as binary numbers
However, when binary sum is more than decimal 9 or
binary (1001)2, the result is invalid (since last 6
combinations have no meaning in BCD)
Addition of 6 =(0110) make a correct BCD and
10 2
produces a carry
BCD Addition
Consider the multibit addition of 184 + 576 = 760 in
BCD:
2. The 2421 Code
2421 code is a weighted
code.
Some digits in 2421 code can
be coded in two possible
ways. E.g. 410 can be written
as 0100 or 1010, since both
combinations add up to a
total weight of 4.
2421 code is self-
complementing, i.e. 9’s
complement of decimal
digital x is simple bit
inversion of its 2421 code.
3. Excess 3 Code
In Excess-3 code, each coded
combination is obtained from
the corresponding binary value
plus 3.
Like 2421, the excess‐3 codes is
also a self‐complementing code
i.e 9’s Comp of decimal number is
simple bit inversion of excess 3
code
Decimal 395 is represented in the
excess‐3 code as 0110 1100
1000. The 9’s complement of 395
is obtained by complementing
each bit of the code, hence
4. The 8,4,-2,-1 Code
The 8, 4, -2, -1 code is an example of assigning both
positive and negative weights to a decimal code.
5. Gray Code
A code where only one bit
changes at a time while
traversing from 0 to any
decimal number in
sequence.
The Gray code is used in
applications in which the
normal sequence of binary
numbers generated by the
hardware may produce an
error or ambiguity during the
transition from one number
to the next.
Character Codes
Many applications require handling of
not only numbers but letters and
special characters
1. ASCII
ASCII refers to American Standard Code for Information
Interchange
ASCII represents each character with a 7-bit string,
yielding a total of 128 characters.
94 are graphic characters that can be printed. The
graphic characters consist of the 26 uppercase
letters (A through Z), the 26 lowercase letters (a
through z), the 10 numerals (0 through 9), and 32
special printable characters, such as %, *, and $.
34 nonprinting characters used for various control
functions like arranging the printed text into a
prescribed format. Examples include Backspace,
Tab, Shift, Space, Escape, Delete, etc
Other Character Codes
EBCDIC (Extended Binary Coded Decimal Interchange
Code) uses 8 bits;
used by IBM mainframes. It is an extension of BCD
code.
Unicode uses 16bits;
Windows NT supports Unicode.
Error Detection Codes
An error in a digital system is the corruption of
data from its correct value to some other
value. i.e., a change of some bits from 0 to 1
or vice versa.
Error Detection Codes
To detect errors in data communication and processing,
an eighth bit is sometimes added to the ASCII character
to indicate its parity. A parity bit is an extra bit included
with a message to make the total number of 1’s either
even or odd.
Even parity – set bit to make total number of 1’s even
(More Common)
A (1000001) with even parity is 01000001
C (1000011) with even parity is 11000011
Odd parity: set bit to make total number of 1’s odd
A (1000001) with odd parity is 11000001
C (1000011) with odd parity is 01000011
Parity Bit Generation
Binary Logic
It consists of binary variables and logical
operations.
AND (multiply)
OR (add)
Not (Compliment)
Logic Gates