HEXADECIMAL NUMBERS
Code
Introduction to
Microprocessors
Number Systems and
Conversions
WRITING one’s and zero’s can be error prone when dealing with large
numbers. IBM came up with the following method of dealing with these
numbers. BASE 16 with digits 0 - 15 in base 10 are represented by the
following notation in Hexadecimal.
016 = 00002 = 010
116 = 00012 = 110
216 = 00102 = 210
316 = 00112 = 310
416 = 01002 = 410
516 = 01012 = 510
616 = 01102 = 610
716 = 01112 = 710
816 = 10002 = 810
916 = 10012 = 910
A16 = 10102 = 1010
B16 = 10112 = 1110
C16 = 11002 = 1210
D16 = 11012 = 1310
E16 = 11102 = 1410
F16 = 11112 = 1510
No. 1-1 9/6/00
Base 16 Conversion
EXAMPLE
Introduction to
Microprocessors
Number Systems and
Conversions
Convert A716 to binary
Note: This is easy because of the relationship between the two bases
A = 1010
7 = 0111
Therefore 0A7H or $A7 = 10100111
Note leading 0 before A.
Since this is a number a different base than base 10,
absence of the zero may confuse a compiler. Therefore it is
customary to add the leading 0 to any hex character that
begins with a letter of the alphabet
(A,B,C,D,E,F) !! These are NUMBERS in base 16 !!
No. 1-2 9/6/00
HEXADECIMAL TO DECIMAL
Introduction to
Microprocessors
Number Systems and
Conversions
• Similar Rules as to those in binary to decimal
– Convert to binary then weighted multiplication -OR– Leave in HEX and use HEX multiplication
• EXAMPLE (repeated multiplication)
$F8E6H = F(16)3 + 8 (16)2 + E(16)1 + 6(16)0
= 15(16)3 + 8 (16)2 + 14(16)1 + 6(16)0
= 61,440 + 2048 + 224 +6
= 63,718
No. 1-3 9/6/00
DECIMAL TO HEXADECIMAL
Introduction to
Microprocessors
Number Systems and
Conversions
• Similar Rules as to those in decimal to binary
Repeated HEX division
• EXAMPLE (repeated division)
• Divisors are for 16 binary digits (4 HEX)
247910 =
2479/16 = 154 remainder 15 or F
154/16 = 9
remainder 10 or A
9/16
remainder 9 or 9
= 9
Answer = 9AFH
No. 1-4 9/6/00
DECIMAL TO HEXADECIMAL
ALTERNATE
Introduction to
Microprocessors
Number Systems and
Conversions
• Same EXAMPLE (but weighted division)
• Divisors are for 16 binary digits (4 HEX)
4096, 256, 16, 1
247910 =
2479/256 = 9 remainder .68359375 x256 =
175/16 = 10 or A remainder .9375 x 16 =
15/1
= 15 or F
Answer = 9AFH
No. 1-5 9/6/00
BINARY CODES
BCD
DECIMAL 8421
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
10 0001 0001
11 0001 0010
....
98 1001 1000
99 1001 1001
4 Bit BCD CODES
BINARY
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100010
1100011
7421
0000
0001
0010
0011
0100
0101
0110
1000
1001
1010
Introduction to
Microprocessors
Number Systems and
Conversions
6311 5421
0000 0000
0001 0001
0011 0010
0100 0011
0101 0100
0111 1000
1000 1001
1001 1010
1011 1011
1100 1100
5311
0000
0000
0011
0100
0101
1000
1001
1011
1100
1101
5211
0000
0001
0011
0101
0111
1000
1001
1011
1101
1111
No. 1-6 9/6/00
MORE 4-BIT BCD CODES
Decimal
0
1
2
3
4
5
6
7
8
9
4221
0000
0001
0010
0011
1000
0111
1100
1101
1110
1111
Introduction to
Microprocessors
Number Systems and
Conversions
3321 2421 84/2/1 74/2/1
0000 0000 0000 0000
0001 0001 0111 0111
0010 0010 0110 0110
0011 0011 0101 0101
0101 0100 0100 0100
1010 1011 1011 1010
1100 1100 1010 1001
1101 1101 1001 1000
1110 1110 1000 1111
1111 1111 1111 1110
The / is subtract
weight
No. 1-7 9/6/00
5-BIT CODES
Decimal 2-out of-5
0
00011
00000
1
00101
00001
2
00110
3
01001
4
01010
10000
5
01100
10000
11110
01000
7
10010
8
10100
Introduction to
Microprocessors
Number Systems and
Conversions
63210 Shift-Counter 86421 51111
00110
00000
00000
00011
00001
00001
00101
01001
01010
00011
00111
01111
00010 00011
00011 00111
00100
01100
6
11000
10010
10100
11111
10001
11100
11000
00101
10001
01001 11100
1-8 9/6/00
10000 No.
11110
OTHER CODES
Introduction to
Microprocessors
Number Systems and
Conversions
• Alphanumeric Codes
– ASCII CODE
– EBCDIC CODE
– UNICODE
7 BITS
8 BITS
16 Bits
No. 1-9 9/6/00
ASCII CODE
Part 1
Introduction to
Microprocessors
Number Systems and
Conversions
R ow
(h ex )
000
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
0000
0
NUL
D LE
SP
0
@
P
`
p
0001
1
SO H
DC1
!
1
A
Q
a
q
0010
2
ST X
DC2
"
2
B
R
b
r
0011
3
ETX
DC3
#
3
C
S
c
s
0100
4
EOT
DC4
$
4
D
T
d
t
0101
5
ENQ
NAK
%
5
E
U
e
u
0110
6
ACK
SY N
&
6
F
V
f
v
0111
7
BEL
ETB
'
7
G
W
g
w
1000
8
BS
CAN
(
8
H
X
h
x
1001
9
HT
EM
)
9
I
Y
I
y
1010
A
LF
SU B
*
:
J
Z
j
z
1011
B
VT
E SC
+
;
K
[
k
{
1100
C
FF
FS
,
<
L
/
l
|
1101
D
CR
GS
-
=
M
]
m
}
1110
E
SO
RS
.
N
^
n
~
1111
F
SI
US
/
O
_
o
DEL
b3b2 b1b
0
?
No. 1-10 9/6/00
ASCII CODE
CONTROL CODES
Introduction to
Microprocessors
Number Systems and
Conversions
NUL
N u ll
D LE
D a ta lin k esca p e
SO H
S tar t of h ea din g
DC1
D evic e c on tr ol 1
ST X
S tar t of tex t
DC2
D evic e c on tr ol 2
ETX
E n d of tex t
DC3
D evic e c on tr ol 3
EOT
E n d of tr an sm ission
DC4
D evic e c on tr ol 4
ENQ
E n q u ir y
NAK
N eg a tive a ckn ow led g e
ACK
A ck n ow led g e
SY N
S yn ch r on iz e
BEL
B ell
ETC
E n d tran sm itted block
BS
B a ck sp a ce
CAN
C an cel
HT
H or iz on tal ta b
EM
E n d of m ed ium
LF
L in e feed
SU B
S u bstitu te
VT
V er tical ta b
E SC
E sca p e
FF
F or m feed
FS
F ile sep ar ator
CR
C arr ia g e r eturn
GS
G r ou p sep ara tor
SO
S h ift ou t
RS
R e c or d sep ara tor
SI
S h ift in
US
U n it sep ar ator
SP
S p a ce
DEL
D elete or r u bou t
No. 1-11 9/6/00
EBCDIC
Part I
Introduction to
Microprocessors
Number Systems and
Conversions
M ost S ig n ific a n t H e xa d e cim a l D ig it
L e a st Sig n ific a n t
D ig it
0
1
2
3
0
N u ll
D a ta lin k esca p e
D ig it select
1
S tar t of h ea din g
D evic e c on tr ol 1
S tar t of
sign ifican ce
2
S tar t of tex t
D evic e c on tr ol 2
F ield sep ara tor
S yn ch r on iza tion
ch ara cter
3
E n d of tex t
T a p e m ark
4
P u n ch off
R est or e
B yp a ss
PN
5
H or iz on tal ta b
N e w lin e
L in e feed
R e c or d sep ara tor
6
L o w er ca se
B a ck sp a ce
E n d of
U p p er ca se
tr an sm ission block
7
D elete
Id le
E sca p e
8
9
5
6
7
/
E n d of
tr an sm ission
C an cel
RLF
\
E n d of m ed ium
A
S tar t of m an ua l
m essa g e
C ur sor con tr ol
S et m od e
B
V er tical ta b
C u stom er u se 1
C u stom er u se 2
C
F or m feed
In ter ch an g e file
sep a ra tor
D
C arr ia g e r eturn
In ter ch an g e gr ou p
sep a ra tor
E n q u ir y
E
S h ift ou t
In ter ch an g e r ecor d
sep a ra tor
A ck n ow led g e
S h ift in
In ter ch an g e un it
sep a ra tor
F
4
Spac
&
e
B ell
cen
t
sig
n
!
|
:
C u stom er u se 3
.
$
,
#
D evic e c on tr ol 4
<
*
%
@
N eg a tive
a ck n ow led g m en t
(
)
_
'
+
;
>
=
S tar t of sp ecia l
seq u en ce
]
| or
? "
or
No.
[ 1-12 9/6/00
]
EBCDIC
PART II
Introduction to
Microprocessors
Number Systems and
Conversions
L east
M ost Significant H exadecim al D igit
Significant
D igit
8
9
A
0
B
C
D
{
}
A
J
E
`
F
0
1
a
j
1
2
b
k
s
B
K
S
2
3
c
l
t
C
L
T
3
4
d
m
u
D
M
U
4
5
e
n
v
E
N
V
5
6
f
o
w
F
O
W
6
7
g
p
x
G
P
X
7
8
h
q
y
H
Q
Y
8
9
i
r
z
I
R
Z
9
A
B
C
D
E
F
No. 1-13 9/6/00
UNICODE
Introduction to
Microprocessors
Number Systems and
Conversions
16 BIT CODE
First Page 0000H - 00FFH Same as ASCII
Has not been standardized the remaining
0FFFFH minus 00FFH available for all remaining
countries and languages!
No. 1-14 9/6/00
Number Systems
Introduction to
Microprocessors
Number Systems and
Conversions
Representation of Negative Numbers
Three major schemes:
sign and magnitude
ones complement
twos complement
nines complement
tens complement
Assumptions:
we'll assume a 4 bit machine word
16 different values can be represented
roughly half are positive, half are negative
No. 1-15 9/6/00
Number Systems
Sign and Magnitude Representation
-7
1111
-6
1110
-5
Introduction to
Microprocessors
Number Systems and
Conversions
+0
+1
0000
0001
+2
1101
0010
+
-4
1100
0011
+3
0 100 = + 4
-3
1011
0100
+4
1 100 = - 4
-2
1010
0101
1001
-1
+5
-
0110
1000
-0
0111
+6
+7
High order bit is sign: 0 = positive (or zero), 1 = negative
Three low order bits is the magnitude: 0 (000) thru 7 (111)
n-1
Number range for n bits = +/-2
-1
Representations for 0
Two +/No. 1-16 9/6/00
Number Systems
Introduction to
Microprocessors
Number Systems and
Conversions
Ones Complement
-0
1111
-1
1110
-2
+0
+1
0000
0001
+2
1101
0010
+
-3
1100
0011
+3
0 100 = + 4
-4
1011
0100
+4
1 011 = - 4
-5
1010
0101
1001
-6
+5
-
0110
1000
-7
0111
+6
+7
Subtraction implemented by addition & 1's complement
Still two representations of 0! This causes some problems
Some complexities in addition
No. 1-17 9/6/00
Number Representations
Introduction to
Microprocessors
Number Systems and
Conversions
Twos Complement
-1
1111
-2
1110
-3
like 1's comp
except shifted
one position
clockwise
+0
+1
0000
0001
+2
1101
0010
+
-4
1100
0011
+3
0 100 = + 4
-5
1011
0100
+4
1 100 = - 4
-6
1010
0101
1001
-7
+5
-
0110
1000
-8
0111
+6
+7
Only one representation for 0
One more negative number than positive number
No. 1-18 9/6/00
BINARY ARITHMETIC
Introduction to
Microprocessors
Number Systems and
Conversions
RULES FOR ADDITION
0+0=0
0+1=1
1+0=1
1 + 1 = 0 + carry 1 to next column
RULES FOR SUBTRACTION
0-0=0
0 - 1 = 1 and borrow from next column
1-0=1
1-1=0
Borrowing 1 from next column is
equivalent to subtracting 1 from that column
No. 1-19 9/6/00
Addition
Introduction to
Microprocessors
Number Systems and
Conversions
EXAMPLE
ADD 1010 to 1101
+
1010
1101
10111
SUBTRACT 1010 from 1101
-
1101
1010
0011
borrow 4 subtract 2
nothing in 4 position
No. 1-20 9/6/00
Number Representations
Introduction to
Microprocessors
Number Systems and
Conversions
Addition and Subtraction of Numbers
Sign and Magnitude
4
0100
When signs is same,
result sign bit is the
+3
same as the operands'
sign. Just add magnitudes 7
-4
1100
0011
+ (-3)
1011
0111
-7
1111
4
0100
-4
1100
-3
1011
+3
0011
1
0001
-1
1001
When signs differ,
operation is subtract,
sign of result depends
on sign of number with
the larger magnitude. This
is what we do in base 10.
No. 1-21 9/6/00
Number Systems
Introduction to
Microprocessors
Number Systems and
Conversions
Sign and Magnitude
Cumbersome addition/subtraction.
Must compare magnitudes to determine the
sign of result.
No. 1-22 9/6/00
Ones Complement
Introduction to
Microprocessors
Number Systems and
Conversions
The symbol N, with a bar over it, is used to represent the
complement. Also used to indicate inversion are /, ‘, or !
(CUPL and ABEL)
N is positive number, then N is its negative 1's complement.
N is the precision, as many 1’s as required. Binary can be
any precision, but BCD requires 4 bits.
Precision 4 bits
Therefore,
The general formula for finding
/N = (2n - 1) - N
2 4 = 10000
-1
= 00001
To find 1's complement of 7
1111
-7
=
0111
1000
= -7 in 1's comp.
No. 1-23 9/6/00
Ones Complement
ZERO
Applying the general formula
/N = (2n - 1) - N
Introduction to
Microprocessors
Number Systems and
Conversions
2 4 = 10000
-1
= 00001
To find 1's complement of 0
1111
-0
=
0000
1111
= -0 in 1's comp.
NOTE:
The complement of 0 is 1111, which means, there are
2 representations of 0.
0000 Positive 0
1111 Negative 0
No. 1-24 9/6/00
SHORTCUT
1’s Complement
Introduction to
Microprocessors
Number Systems and
Conversions
Shortcut method:
Replace all 0’s with 1’s, and all 1’s with 0’s
simply compute bit wise complement
7 in 1’s complement
0111 -> 1000
No. 1-25 9/6/00
Number Systems
Introduction to
Microprocessors
Number Systems and
Conversions
Addition and Subtraction of Numbers
Ones Complement Calculations
4
0100
-4
1011
+3
0011
+ (-3)
1100
7
0111
-7
10111
End around carry
1
1000
4
0100
-4
1011
-3
1100
+3
0011
1
10000
-1
1110
End around carry
1
0001
No. 1-26 9/6/00
Number Systems
Addition and Subtraction of Binary Numbers
Ones Complement Calculations
Introduction to
Microprocessors
Number Systems and
Conversions
Why does end-around carry work?
n
Its equivalent to subtracting 2 and adding 1
For (M > N)
M - N = M + / N = M + (2n - N -1) = (M - N) + 2n - 1
For M + N < 2n-1
-M + (-N) = M + N = (2n - M - 1) + (2n - N - 1)
= 2n + [2n - 1 - (M + N)] - 1
after end around carry the -1 is canceled if a carry, else not:
= 2n - 1 - (M + N)
this is the correct form for representing -(M + N) in 1's complement!
No. 1-27 9/6/00
Number Systems
Two’s Complement Numbers
Introduction to
Microprocessors
Number Systems and
Conversions
/N = 2n - N
4
Note: subtract number immediately.
Example: Twos complement of 7
2 = 10000
sub 7 =
0111
1001 = represents -7
Example: Twos complement of 0
Only 4bits can represent number.
The most significant 1 is dropped!
4
2 = 10000
sub -0 =
0000
0000 = 0
Shortcut method Number 1:
Twos complement =1’s complement + 1
0111 -> 1000 + 1 -> 1001 (representation of -7)
1001 -> 0110 + 1 -> 0111 (representation of 7)
No. 1-28 9/6/00
SHORTCUT
Introduction to
Microprocessors
Number Systems and
Conversions
Shortcut method Number 2:
Starting from the right, least significant bit, if 0 leave unchanged.
Continue from right to left, if 0, no change. When the first 1 is encountered,
we leave it unchanged, but complement each digit to the left.
710 = 01112 Apply method 10012 = -710 .
6810 = 011001002
yields 100111002 . The lead 0 is important so that
the number to be converted
is positive! In base 10, the - sign
does that for us. With only on and
off (0,1) we need this extra bit
of information to describe the
signed number.
-6810 = 10011100 yields 011001002 = + 6810
No. 1-29 9/6/00
Number Systems
Addition and Subtraction of Binary Numbers
Twos Complement Calculations
Introduction to
Microprocessors
Number Systems and
Conversions
4
0100
-4
1100
+3
0011
+ (-3)
1101
7
0111
-7
11001
4
0100
-4
1100
-3
1101
+3
0011
1
10001
-1
1111
Simpler addition scheme makes twos complement the most common
choice for integer number systems within digital systems
No. 1-30 9/6/00
Number Systems
Addition and Subtraction of Binary Numbers
Twos Complement Calculations
Introduction to
Microprocessors
Number Systems and
Conversions
Why can the carry-out be ignored?
-M + N when N > M:
n
n
M* + N = (2 - M) + N = 2 + (N - M)
Ignoring carry-out is just like subtracting 2
n
-M + -N where N + M < or = 2 n-1
n
n
-M + (-N) = M* + N* = (2 - M) + (2 - N)
n
n
= 2 - (M + N) + 2
After ignoring the carry, this is just the right twos compl.
representation for -(M + N)!
No. 1-31 9/6/00
Number Systems
Introduction to
Microprocessors
Number Systems and
Conversions
Overflow Conditions
Add two positive numbers to get a negative number
or two negative numbers to get a positive number
-1
-2
1111
0001
1101
-4
0010
1100
-5
0100
1010
0101
1001
-7
0110
1000
-8
0111
+7
+3=-8 (error)
4 bit representation
3 bits + sign in msb
range -8 to +7
-3
+2
0011
1011
-6
-2
+1
0000
1110
-3
-1
+0
+3
-4
1111
1110
1101
+2=7 (ok)
0010
1010
-6
0110
1000
-8
+2
0011
+3
0100
+4
0101
1001
-7
+1=6 (ok)
0001
1011
+4
+6
+1
0000
1100
-5
+5
+0
0111
+5
+6
+7
-7 - 2 = +7
5 0101
+3 0011
-8 1000
No. 1-32 9/6/00
OVERFLOW
Introduction to
Microprocessors
Number Systems and
Conversions
If carry-in (penultimate) is added
to sign bit and there is a carry-out
then no overflow.
if carry-in differs from
carry-out then overflow
This is true for both 1’s and 2’s complement addition.
No. 1-33 9/6/00
Number Systems
Overflow Conditions
Example is using 2’s Complement
0 1 1 1 carry
5
0101
3
0011
-8
1000
Overflow
Introduction to
Microprocessors
Number Systems and
Conversions
-7
1 0 0 0 carry
1001
-2
1110
7
10111
Overflow
Note: the carry and penultimate carry are not the same!
This can be very easily implemented in hardware. XOR
5
0 0 0 0 carry
0101
-3
1 1 1 1 carry
1101
2
0010
-5
1011
7
0111
-8
11000
No overflow
No overflow
Overflow when carry in to sign does not equal carry out
No. 1-34 9/6/00
BCD Addition
Introduction to
Microprocessors
Number Systems and
Conversions
BCD Number Representation
Decimal digits 0 thru 9 represented as 0000 thru 1001 in binary
Addition:
5 = 0101
3 = 0011
1000 = 8
5 = 0101
8 = 1000
Problem
when digit
sum exceeds 9
1101 = 13!
Solution: add 6 (0110) if sum exceeds 9.
5 = 0101
9 = 1001
8 = 1000
7 = 0111
1101
6 = 0110
1 0011 = 1 3 in BCD
1 0000 = 16 in binary
6 = 0110
1 0110 = 1 6 in BCD
No. 1-35 9/6/00
BCD Subtractin
Introduction to
Microprocessors
Number Systems and
Conversions
Must use 10’s complement
To find 10’s complement, first generate 9’s complement by subtracting
The number from 9.
If n = 9,
If n = 8,
If n = 7,
If n = 6,
If n = 5,
If n = 4,
If n = 3,
If n = 2,
If n = 1,
If n = 0,
9-9 =0
9-8 =1
9-7 =2
9-6 =3
9-5 =4
9-4 =5
9-3 =6
9-2 =7
9-1 =8
9-0 =9
9’s complement of 9 is 0 or 0000
9’s complement of 8 is 1 or 0001
9’s complement of 7 is 2 or 0010
9’s complement of 6 is 3 or 0011
9’s complement of 5 is 4 or 0100
9’s complement of 4 is 5 or 0101
9’s complement of 3 is 6 or 0110
9’s complement of 2 is 7 or 0111
9’s complement of 1 is 8 or 1000
9’s complement of 0 is 9 or 1001
Add 1 to 9’s complement to find 10’s complement.
No. 1-36 9/6/00
Example of BCD Subtract
Introduction to
Microprocessors
Number Systems and
Conversions
To subtract 2 from 5, find 10’s complement of 2 which is 10002 4 Bit
Representation.
5
-2
5
8
3
13
0101
1000
1
1101 The 1 carry, is normal form
and indicates answer is 3.
In binary, 1001 is exceeded!
Must add 6 to correct.
Known as BCD adjust.
0110
0011 The 1 carry is normal form
answer is 3 base 10.
No. 1-37 9/6/00
Addition Examples
4 BITS signed and
unsigned
Introduction to
Microprocessors
Number Systems and
Conversions
D e c im a l
B in a ry
U n s ig n e d
1 ’s
C o m p le m e n t
2 ’s
C o m p le m e n t
9 ’s
C o m p le m e n t
1 0 ’s
C o m p le m e n t
9 ’s
C o m p le m e n t
B in a ry
Coded
D e c im a l
1 0 ’s
C o m p le m e n t
B in a ry
Coded
D e c im a l
N o S ig n
N o S ig n
4 B it
S ig n e d
No
O ve rflo w
4 B it
S ig n e d
No
O ve rflo w
B a s e 10
S ig n e d
No
O ve rflo w
B a s e 10
S ig n e d
No
O ve rflo w
B ase2
S ig n e d N o
O ve rflo w
4 B it B C D
B ase2
S ig n e d N o
O ve rflo w
4 B it B C D
0001
0011
0001
0011
1
+3
0001
0011
0
0 1
0001
0011
0
1
4
0100
5
+7
4 B it
N o S ig n
No
O ve rflo w
0101
0111
0
12
1 1 1
1100
0 1 1
0001
0011
0
0100
4 B it
S ig n e d
O ve rflo w
1 1 1
4 B it
S ig n e d
O ve rflo w
1100
0101
0111
0
1
+3
0 1 1
0
0100
0101
0111
0
1
+3
4
B a s e 10
S ig n e d
O ve rflo w
05
+07
5
+7
1 1 1
1100
12
0 1 1
B a s e 2 9 ’s
S ig n e d
O ve rflo w
4 B it B C D
0101
0111
B a s e 2 1 0 ’s
S ig n e d
O ve rflo w
4 B it B C D
0101
0111
0
12
0
0100
4
B a s e 10
S ig n e d
O ve rflo w
0 1 1
0100
1 1 1
1100
0
1 1 1
1100
No. 1-38 9/6/00
Addition Examples
4 BITS signed and
unsigned
D e c im a l
B in a r y
U n s ig n e d
1 ’s
C o m p le m e n t
N o S ig n
N o S ig n
4 B it
S ig n e d
No
O ve rflo w
7
-2
2 ’s
C o m p le m e n t
4 B it
S ig n e d
No
O ve rflo w
0111
1101
1
1 1 1
0111
1110
1
1 1 1
0100
1
0101
5
4 B it
S ig n e d
No
O ve rflo w
5
-7
0101
4 B it
S ig n e d
No
O ve rflo w
0101
1000
0
-2
Introduction to
Microprocessors
Number Systems and
Conversions
0 0 0
1101
0
1101
(-2 ) 0 0 1 0
0101
1001
0
9 ’s
C o m p le m e n t
1 0 ’s
C o m p le m e n t
9 ’s
C o m p le m e n t
B in a r y
Coded
D e c im a l
1 0 ’s
C o m p le m e n t
B in a r y
Coded
D e c im a l
B a s e 10
S ig n e d
No
O ve rflo w
B a s e 10
S ig n e d
No
O ve rflo w
B ase2
S ig n e d N o
O ve rflo w
4 B it B C D
B ase2
S ig n e d N o
O ve rflo w
4 B it B C D
0111
1101
0111
1110
7
97
1 1
7
98
1 1
04
1
05
B a s e 10
S ig n e d
No
O ve rflo w
05
92
B a s e 10
S ig n e d
No
O ve rflo w
5
93
0 0 1
1110
0001
1
(-2 ) 0 0 1 0
1
05
98
-2
01
1
(-2 ) 0 2
1
1 1 1
0100
1
0101
0101
B a s e 2 9 ’s
S ig n e d
No
O ve rflo w
4 B it B C D
0101
1000
B a s e 2 1 0 ’s
S ig n e d
No
O ve rflo w
4 B it B C D
0101
1001
0
97
1 1 1
0 0 0
1101
0
1101
(-2 ) 0 0 1 0
0
0 0 1
1110
0001
1
(-2 ) 0 0 1 0
No. 1-39 9/6/00
Excess 3 Code
Introduction to
Microprocessors
Number Systems and
Conversions
Excess-3 code is another important BCD Code.
To encode a decimal number, add 3 to each digit
before converting to binary.
EXAMPLE (Note: 2 digits represented by 2 4 bit
numbers)
12 to excess-3 = 1+3=4
2+3=5
4
5
0100 0101
29
to excess-3 = 2+3=5 9+3=12
5
12
0101 1100
No. 1-40 9/6/00
EXAMPLES OF EXCESS ADDITION
Introduction to
Microprocessors
Number Systems and
Conversions
CASE 1
In excess-3 addition, whenever we add two numbers
whose sum is 9 or less, an excess-6 number is
formed. To return to excess-3 we must subtract 3.
EXAMPLE
2 +5 = 7
0101 2
1000 5
1101 excess-6
- 0011
1010 excess-3 equivalent of 7
No. 1-41 9/6/00
EXAMPLES OF EXCESS ADDITION
CASE 2
Introduction to
Microprocessors
Number Systems and
Conversions
In excess-3 addition, whenever we add two numbers
whose sum is greater than 9, there will be a carry
from one group to the next. When this happens, the
group that produced the carry will revert to 8421
(BCD). To return to excess-3 we must subtract 3
from that group.
EXAMPLE
0
1
carry not carried to 10’s because of sum
29 0101 1100 excess-3 for 29
+ 39 0110 1100 excess-3 for 39
68 1100 1000 first result
- 0011 + 0011 subtract less than 9, add 3
1001
1011 excess-3 for 68
No. 1-42 9/6/00
Descargar

Arithmetic Circuits Fundamentals Of Logic Design