EE314 Microprocessor Systems Appendix 1 Number Systems

Download Report

Transcript EE314 Microprocessor Systems Appendix 1 Number Systems

EE314
Microprocessor Systems
Appendix 1
Number Systems
Objectives:
Review of number systems and radix conversion methods
Review of binary, octal, hexadecimal and BCD unsigned codes
Review of binary bipolar (signed) codes
A1.1 Review of number systems
r-radix numbers
Each digit in a decimal number caries two meanings:
645.39210  6 10 2  4 101  5 100  3 10 1  9 10 2  2 10 3
The value
The 10 radix
The weight given by the 10i , where i represent the
(base)
position of the digit relative to the (decimal) point.
(0...9)
For any radix r, the value of a number with n-digit integer part and m-digit fraction part,
can be expressed:
n 1
(a a ...a a .a a ...a
a ) 
a  r i (A1.1)
n 1
The digit value
(0...r  1)
n2
1 0
The position
relative to
the radix
point.
1
2
 ( m 1)
The used
radix (base)

m r
i  m
i
The weight given by the ri ,
where i represent the
position of the digit relative
to the (decimal) point.
In electronic circuits, the 2 radix is used, associating the two possible digit values to
the presence (1) or absence (0) of an electrical signal (voltage) on a transmission line.
(an 1an  2 ...a1a0 .a1a 2 ...a( m 1) a m ) 2 
Binary digiT=bit
n 1
i
a

2
 i
i  m
(A1.2)
A1.1 Review of number systems
Binary-Coded Hexadecimal and Binary-Coded Octal numbers
Large radix 2 numbers are difficult to analyze by a human observer. Octal numbers
(Radix 8) or hexadecimal numbers (radix 16) are used instead. Radix 8 representation
uses 8 different digits (0…7). Radix 16 uses 16 different digits (0…9, A, B, C, D, E, F).
Decimal
value
Binary
value
Octal
value
0
1
2
3
4
5
6
7
Hexadecimal
value
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Every octal digit can be expressed
using 3 bits, every hexadecimal digit,
0
0
using 4 bits.
1
1
2
10
The conversion from radix r=2k to
3
11
radix 2 is direct. Every 2k -digit is
4
100
replaced by the k-bit binary number
5
101
6
110
having the same value. The reverse
7
111
conversion groups the bits in packets
8
1000
of k, beginning from the radix point,
9
1001
10
1010
and end replacing each group with
11
1011
its corresponding 2k -digit.
12
1100
BCH = Binary-Coded Hexadecimal
13
1101
BCO = Binary-Coded Octal
14
1110
15
1111
Zeros to complete
group of k bits
71F.B816  71F.B8H  0111,0001,1111.1011,1000BCHthe Radix
point
Separators: “,” or” “
261.528  261.52O  010,110,001.101,010BCO
A1.1 Review of number systems
Binary-Coded Decimal numbers
Octal numbers or hexadecimal numbers are unusual to a human observer. A way to
electrical representation of decimal numbers is the BCD code = Binary-Coded Decimal.
Each decimal digit is replaced by the corresponding binary 4 bit number. Bit
combinations 1010…1111 are forbidden.
The conversions BCD <-> Decimal are direct and similar to
Decimal
BCD
digit
digit
BCH <-> Hexadecimal conversions.
0
0000
The conversions BCD <-> Binary are NOT direct (in contrast with
1
0001
BCH <-> Binary and BCO <-> Binary who are direct)
2
0010
Zeros to complete
3
0011
4
0100
the group of k bits
5
6
7
8
9
0101
0110
0111
1000
1001
715.0810  0111,0001,0101.0000,1000BCD
Decimal point
Separators: “,” or” “
A1.1 Review of number systems
Conversion between decimal and r-radix numbers
Performed in decimal arithmetic.
r-radix ->decimal
(an 1an  2 ...a1a0 .a1a 2 ...a( m 1) a m ) r 
Examples
n 1
i
a

r
 i
(A1.1)
i  m
1101.0012  1 23  1 2 2  0  21  1 20  0  2 1  0  2 2  1 2 3 
 8  4  1  0.125  13.12510
F1.8H  15 161  1 160  8 16 1  240  1  0.5  241.510
decimal -> r-radix
A  (an 1an  2 ...a1a0 .a1a 2 ...a( m 1) a m ) r 
n 1
A  Ip  Fp; Ip   ai  r ; Fp 
i
i 0
n 1
n 1
i  m
i 0
i
i
a

r

a

r
 i
 i 
1
i
a

r
 i
i  m
1
i
a

r
 i ;
i  m
Integer
part
Fraction
part
A1.1 Review of number systems
n 1
Integer decimal to r-radix conversion
Ip   ai  r i  a0  r  (a1  r  (a2  ...  r  (an  2  r  (an 1 ))...)) ai  r
i 0
Dividend  divizor  qoutient  remainder
Step
0
1
2
Dividend
a0+r(…)
a1+r(…)
a2+r(…)
n-2
n-1
an-2+r(an-1)
an-1
Divizor Quotient Remanider
r
a1+r(…)
a0
r
a2+r(…)
a1
r
a3+r(…)
a2
r
r
an-1
0
Ipr  (an 1an 2 ...a1a0 ) r
an-2
an-1
Examples:
Dec.->Bin.
Divid. Rem.
47
1
23
1
11
1
5
1
2
0
1
1
0
Dec.->Hex.
Divid. Rem.
800
0
50
2
3
3
0
80010  32016
4710  1011112
A1.1 Review of number systems
Fraction decimal to r-radix conversion
1
Fp 
i
1
1
1
1
a

r

r

(
a

r

(
a

...

r

(
a

r
 (a m ))...))  
 i
1
2
 ( m 1)
i  m
m
  r ; r  Fp  a1  r 1  (a2  ...  r 1  (a( m1)  r 1  (am ))...)    r
Ex: Dec.->Bin.
Step
1
Multiplicand
-1
-1
r (a-1+r (…))+
2
r (a-2+r (…))+ r
-1
-1
2
r (a-3+r (…))+ r
-1
3
-1
-1
1
-1
m-2
m-1
r (a-(m-1)+r (a-m)+ r
m
r (a-m)+ r
-1
m-1
Multiplier
r
Ip of
product
a-1
r
a-2
r
a-3
r
a-(m-1)
r
a-m
Fpr  (0.a1a 2 ...a( m 1) a m ) r
Fp of product
-1
-1
1
r (a-2+r (…))+ r
-1
-1
2
r (a-3+r (…))+ r
-1
-1
3
r (a-4+r (…))+ r
-1
m-1
r (a-m+)+ r
m
r
Mpd. Ip p.
0.4
0
0.8
1
0.6
1
0.2
0
0.4
0
0.410  0.011002
Dec.->Hex.
Mpd. Ip p.
0.4
6
0.4
6
0.410  0.(6)16
A1.1 Review of number systems
Signed (Bipolar) integer binary numbers
Decimal
value
8
7
6
5
4
3
2
1
0
-0
-1
-2
-3
-4
-5
-6
-7
-8
Unsigned
value
111
110
101
100
011
010
001
000
-
Signed
magnitude
0111
0110
0101
0100
0011
0010
0001
0000
1000
1001
1010
1011
1100
1101
1110
1111
-
1's
complement
0111
0110
0101
0100
0011
0010
0001
0000
1111
1110
1101
1100
1011
1010
1001
1000
-
Sign bit Magnitude
To change
the sign:
Complement
the sign bit.
Excess
(Offset)
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000
2's
complement
0111
0110
0101
0100
0011
0010
0001
0000
1111
1110
1101
1100
1011
1010
1001
1000
Sign bit
Complement
all bits.
Complement all bits
and add 1 LSB.
Examples:
Signed magnitude:
0101<->1101
1’ complement:
0011<->1100
Excess:
0010
1101+
1
1110
1110
0001+
1
0010
2’ complement:
0101
1010+
1
1011
1011
0100+
1
0101