Download Representing numbers in different bases

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Representing numbers in
different bases
In base r
D = an-1 an-2 … a0 . a-1 a-2 …
In base 10:
N = an-1 * rn-1 + an-2 * rn-2 + … + a0 +
a-1*r-1 + a-2*r-2 + …
Representing numbers in
different bases
Convert:
(0.41)10 to ()4
Representing numbers in
different bases
0.41
= an-1 * 4n-1 + an-2 * 4n-2 + … + a0 +
a-1*4-1
0.41
+ a-2 * 4-2 + …
= a-1*4-1 + a-2* 4-2 + …
=0
Representing numbers in
different bases
0.41
= a-1*4-1
+ a-2 * 4-2 + …
4
1.64
= a-1
+ a-2 * 4-1 + a-3
<1
a-1 = 1
* 4-2
Complement to Base r
Definition:
Number
D
n=4
(1101)2
n=2
(12)10
n digits
xxxxxxxx
m digits
.
r-complement
yyyyyy
2-complement
10-complement
rn - D
24
10000-1101 =0011
102
100-12 = 88
Complement-1 to Base r
Definition:
Number
D
n=3 m=2
(1101.11)2
n=1
(12)10
n digits
xxxxxxxx
m digits
.
yyyyyy
1-complement
9-complement
(r-1) complement
rn-r-m - D
1111.11-1101.11 =0010.00
99-12 = 87
Another representation of 2
complement
BCD Weight: 2n-1
2-complement
Weight:
-2n-1
an-1 an-2 … a0 . a-1 a-2 …
BCD Coding
Two complement
1101 =
- 0011
-23 + 22 + 1
-3
Calculating the r complement
r complement
(r-1) complement
rn-r-m - D
+r-m
rn - D
+1
0011
Number (base 2): 1101
1-complement:
0010
0 in complement to 1
Number
1-complement
00000
11111
Two representations to 0!
Complement to 1 vs. 2
Calculation
Zero preserntation
1-Complement 2-Complement
Easy
Harder
Dual
Singe
We usually use 2-complement
Subtraction using 1-complement
M–N
M>N-1
Carry
M + 2n-N-1 = 2n+(M-N-1)
M<N-1
<0
>0
2n+(M-N-1)
2n+(M-N-1)
Carry exists
Add it to the result
No Carry
Take the complement and put (-)
-[ 2n – (2n+(M-N-1)) -1 ]
(M-N)
-(N-M)
Example I
3
-5
No Carry
0011
+1010
101
-010 = -2
Example II
3
-2
Carry
1
011
+101
000
1
001
Changing number of bits
Given a number in 2 complement with n bits
What is the representation with m>n bits ?
Changing number of bits
0011
1011
00 0011
11 1011
Binary Multiplication
1101
X 0011
1101
1101
100111
13
X 03
39
2-Complement multiplication
-3
X
5
Carry
1
1101
X
0101
111101
00000
1101
110001
2-Complement multiplication
-3
X
-5
1101
X
1011
?????
2-Complement multiplication
-3
X
-5
Remember:
Last digit has
negative weight
1101
X
1011
1111101
111101
00000
0011
0001111
=15
Related documents