FAC1002 - Computer Codes
FAC1002 - Computer Codes
Computer Codes
Ruhaila Md Kasmani
Pusat Asasi Sains, Universiti Malaya
We naturally live in a base 10 environment
Computer exist in a base 2 environment
So give the computer/digital system the task of doing the
conversions for us.
Computer
Codes
Binary Format
HOW DOES A COMPUTER REPRESENT THE NUMERICAL
DATA IN BINARY FORMAT?
(1) Base-2 digits [Straight Binary]
(2) BCD [Binary-Coded Decimal]
Straight Previous
Binary Lecture (MZ)
8-bit BCD
4-Bit BCD CODES
BCD Codes
Non-Weighted
Weighted 8-4-2-1 BCD
XS-3
Very useful in digital systems whenever Not appropriate to use in digital system
floating point number information is
given either as inputs or displayed as
outputs.
Examples: Examples:
(1) 410 = 0100 (4-bits) (1) 410 = 100 (3-bits)
(2) 1210 = 0001 0010 (8-bits) (2) 1210 = 1100 (4-bits)
4-Bit BCD : Conversion
Example 1: Convert the following decimal numbers to
its equivalent 4-bit BCD code
0 1 0 0
+ 0 0 0 1
0 1 0 1
1 1
0 0 1 1
+ 0 0 1 1
0 1 1 0
+ 0 1 0 1 1 1 1
1 0 1 0 1 0 1 0
+ 0 1 1 0
1 0 0 0 0
But 1010= 1010 is NOT in
the list of 4-bit BCD The answer is 0001 0000 which is
representation. equivalent to 1010.
Why Do We Add 6 (0110) in 4-bit BCD Addition
1 1 1 1 1 1 1
0 1 0 0 0 0 0 1 0 1 1 1
+ 0 0 0 1 1 0 0 1 0 1 0 1
0 1 1 0 1
1 1
0 1 1 11 1 0 0
Md 0 1 1 0 0 1 1 0
0 1 1 0 0 0 0 1 0 0 1 0
Weighted
4-3-1-1 Code
Codes
XS-3 Code
Non-Weighted
Codes
Gray Code
4-BIT BCD CODES
DECIMAL DIGITS
Weighted 8-4-2-1 Non-Weighted XS-3
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
Table : the binary representation for 4-bit codes in XS-3
Non-Weighted XS-3 BCD : Conversion
Example 7: Find the equivalent value of 46910 in
non-weighted XS-3 BCD.
46910 = 0100 0110 1001 in weighted 8-4-2-1 BCD.
To obtain XS-3 BCD, we add 0011 for each digit of 8-4-2-1 BCD.
1 1 1 1
0 1 0 0 0 1 1 0 1 0 0 1
+ 0 0 1 1 0 0 1 1 0 0 1 1
0 1 1 1 1 0 0 1 1 1 0 0
BCD
Codes
Numeric Even
Zone Bits Odd Parity
Bits Parity
6-bit BCD Codes
Introduction
Why 6-Bit
4-bit BCD codes are Parity Bit
inadequate for representing
Six-bit BCD codes come
and handling non-numeric
with additional parity bit.
data. For this purpose, 6-bit
BCD code has been
developed.
Memory cells representation of 6-bit BCD code can be
divided into two which are zone bits and numeric bits.
B A 8 4 2 1 6-bit cells
8-4-2-1
0 00 0 0 00
1 00 0 0 01
2 00 0 0 10
3 00 0 0 11
4 00 0 1 00
5 00 0 1 01
6 00 0 1 10
7 00 0 1 11
8 00 1 0 0 0
9 00 1 0 0 1
8-4-2-1
A 01 0 0 01
B 01 0 0 10
C 01 0 0 1 1
D 01 0 1 0 0
E 01 0 1 0 1
F 01 0 1 1 0
B A 8 4 2 1 6-bit cells
C B A 8 4 2 1
7-bit cells
Check Bit –Two variants of parity bits: even parity bit and odd parity bit
Character Check bit Zone bit Numeric bit Total number of 1’s
7 0 00 0111 3 (odd) check bit is 0
P 1 10 0111 4 (even) check bit is 1
W 0 01 1100 3 (odd) check bit is 0
9 1 00 1001 2 (even) check bit is 1
6-Bit BCD Code : Parity
Example 9:
The following table shows the zone bits and numeric bits of 6-bit BCD code
for the characters, EURO2016. If the computer uses an even parity check to
encode the characters, find the check bit for each character.
Character E U R O 2 0 1 6
Check bit
Zone bits 11 01 10 10 00 00 00 00
Numeric bits 0101 0100 1001 0110 0010 1010 0001 0110
Solution:
Check bit 0 0 1 1 1 0 1 0
8-Bit BCD CODES
BCD
Codes
Representation Examples
Zone Numeri
EBCDIC ASCII
Bits c Bits
WHY 8-BIT BCD CODES WERE BEING CREATED?
Z Z Z Z 8 4 2 1
Binary Format
Previous
Lecture (MZ)
Zoned Decimal & Packed Decimal Formats
Computer code format is used to identify the sign of decimal numbers.
Each byte of storage is divided into Each byte of storage (except for the
two portions: a 4-bit zone portion low order byte) can contain decimal
and a 4-bit digit portion numbers
8 bit = 1 byte
byte
Zoned Decimal Format
Example 10 :
Encode the numbers 275, +275 and –275 in
zoned decimal format.
275
2 7 + 5
– 275
2 7 – 5
Example 11:
0010 0111 0101 1111
Illustrate the packed-
decimal format of
2 7 5
memory cell in computer
+
for the number 275,
0010 0111 0101 1100 +275 and −275
2 7 5 –
2 1 5 4 + 4
1111 0010 1111 0001 1111 0101 1111 0100 1100 0100
5 bytes
2 1 5 4 4 +
3 bytes
COMPUTER CODES
Computer
Codes
BCD
Formats
Codes
Zoned Packed
4-Bit 6-Bit 8-Bit
Decimal Decimal
Weighted Non-
8-4-2-1 Weighted Representation Check Bit Representation Examples
BCD XS-3 BCD