You are on page 1of 7

BINARY CODES FOR DECIMAL DIGITS

Binary codes are used to represent distinctly


all members among a group of quantities.
Generally, if there are n quantities in a group, a
code of b binary digits or bits may represent all
quantities uniquely.

n 2b
Example: 10 decimal digits (0-9) can be
represented by 4-bit binary code.

(A) WEIGHTED BINARY


(WEIGHTED BCD)

CODE

FOR

DECIMAL

DIGITS

Natural BCD (8421 code)


Used whenever decimal information is transferred in or out of a
digital system.
Straight assignment of binary equivalent is used with weights
8-4-2-1.
84-2-1 code, 2421 code
Weighted, reflected and self-complementing codes.
In 2421 code, if a number has more than one representation, choose
the code that uses the lower binary weights (for numbers 0 to 4 only).
5421 code
Weighted code with weights 5-4-2-1.
In 5421 code, if a number has more than one representation, choose
the code that uses the lower binary weights.

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 1

7421 code
Weighted code with weights 7-4-2-1.
For decimal number 7, choose code with least number of 1s.
Biquinary code
Weighted code with weight 5-0-4-3-2-1-0.
A seven-bit code with error-detection properties.
Each decimal digit consists of (5) 0s and (2) 1s placed in the
corresponding columns.
Always use weights 5 or 0 at the left side.
5311 code
Weighted code with weights 5-3-1-1.
In 5311 code, if a number has more than one representation, choose
the code with least number of 1s and use first the 1 from extreme
right.
DECIMAL
5311
NUMBER
0
0000
1
0001
2
0011
3
0100
4
0101
5
1000
6
1001
7
1011
8
1100
9
1101

(B) UNWEIGHTED BINARY CODE FOR DECIMAL DIGIT


(UNWEIGHTED BCD)

Excess 3 (XS3) code


It is obtained by adding 3 (0011 in binary) to the 8421 code.
It is reflected, self-complementing code.
DECIMAL
EXCESS 3
NUMBER
CODE
0
0011
1
0100
2
0101
3
0110
4
0111
5
1000
6
1001
7
1010
8
1011
9
1100

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 2

(C) GRAY CODE


-

It is also known as the reflected and unit distance code.


Reflected: mirror image
Unit distance: exhibits only a single bit change from one code to the
next.
It is also an unweighted and not an arithmetic code.

DECIMAL
NUMBER
0
1
2
3
4
5
6
7

GRAY CODE

DECIMAL
NUMBER
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

GRAY CODE

000
001
011
010
110
111
101
100

0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000

Binary to Gray Code Conversion


1) Place a leading zero before the MSB.
2) Compare the adjacent bit starting from the leading zero.
3) If the two compared bits are the same
0, if not
1
examples:

1 0 1
0 1 0 1
1 1 1

Binary
Gray Code

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 3

14

1 1 1 0
0 1 1 1 0
1 0 0 1

Binary
Gray Code

Gray Code to Binary Conversion


1) Drop the MSB.
2) Compare this to the next adjacent bit.
3) If the compared bits are the same
0, if not
examples:

14

1 1 1
/ /
1 0 1

Gary Code

1 0 0 1
/ / /
1 1 1 0

Gray Code

Binary

Binary

(D) ERROR DETECTION CODE


-

Used to detect error in digital circuit, especially during transmission


of bits from one location to the other.
Systems use a parity bit as a means for bit error detection. Error
detection codes contain either an even or an odd number of 1s.
A parity bit is an extra bit attached to a group of bits to make the
total number of 1s in a group either even or odd.
ODD PARITY
EVEN PARITY

number of 1s is odd
number of 1s is even

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 4

(E) ALPHANUMERIC CODES


-

Alphanumeric codes are codes that represent numbers and alphabetic


characters (letters). Most such codes, however, also represent other
characters such as symbols and various instructions necessary for
conveying information.

ASCII American Standard Code for Information Interchange


It is a universally accepted alphanumeric code used in most
computers and other electronic equipment.
ASCII has 128 characters and symbols represented by a 7-bit binary
code.
ASCII can be considered an 8-bit code with the MSB zero or in data
communication system; the MSB is reserved for parity.
The first thirty-two are non-graphic commands that are never printed
or displayed and used only for control purposes.
It allows manufacturers to standardize I/O hardware such as
keyboard, printer and video display.

EBCDIC Extended Binary Coded Decimal Interchange Code


It is an 8-bit character code developed by IBM.
It is used in IBM equipment to represent characters and symbols.

ASCII TABLE

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 5

EBCDIC TABLE

NOTES004 BINARY CODE FOR DECIMAL DIGITS


DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 6

DRILL PROBLEMS
I. Fill the table below.
DEC NBCD 84-2-1
CODE

2421
CODE

5421
CODE

5311
CODE

XCS-3
CODE

BIQUINARY

GRAY
CODE
0110

1001
0111
1111
1001000

II. Express the word COE in ASCII using even parity generator and odd parity generator.
Answer:
ASCII with even parity =____________________________________________2
ASCII with odd parity = ____________________________________________2

REFERENCES
[1] Thomas, Floyd L., Digital Fundamentals, 4th Edition, Macmillan Publishing
Company, New York, 1990
[2] Mano, M. and Kime, C., Logic and Computer Design Fundamentals, 2nd Edition,
Prentice Hall Intl., N.J., 2001
[3] Mano, M., Digital Design, 2nd Edition, Prentice Hall, N.J, 1991
[4] Hall, D., Microprocessors and Interfacing: Programming and Hardware, 2nd
Edition, Glencoe Division of Macmillan/McGraw-Hill School Publishing Company,
1992
[5] Tocci, R. and Widmer, N., Digital Systems: Principles and Applications, 8th
Edition, Prentice Hall Inc., N.J., 2001
[6] Swidlec Lecture Notes by Edzel Lapira, DLSU
NOTES004 BINARY CODE FOR DECIMAL DIGITS
DIGITAL SYSTEM I LECTURE NOTES by Engr. Analene Montesines-Nagayo

PAGE 7

You might also like