Professional Documents
Culture Documents
Outline
.a a
a =
N= amam-1....a1ao
-1 -2 -n
Integer part: m+1 digits
Radix (base)=
2
m
1
0
N= am 2 + am-1 2m-1 + aExample:
2
+
a
2
1
0
-2
-n
1101.011
i -1 + a
+
a
2
2
+a
2
N= (ai-1 2 )
-2
-n
i=-nm
ai = 0 or 1
23 22
20
2-2 2-3
m=3
n=3
m, n positive integers
3
23+22+20
8
Assign:
12
= 23 + 22 + 20= 1310
1
5
13 =
1101. =
8+4+1
6.5 = 110.1 =
4 + 2 + 0.5
3.25 = 11.01 =
2 + 1 + 0.25
7
LSB
8
Decimal
(base=10)
10
digits
9
8
7
6
5
4
3
2
1
0
Binary (base=2)
2
digits
27/2=13, remainder 1
1
0
13 = 1101
No need to convert 13
since we remember the result
1 1 0 1 1 0 1 02 = 27 + 26 + 24 + 23 + 21
7
6 5
3 2
1 0
Fractional parts
Decimal numbers
10-1 10-2
.7
7 0.1 + 5 0.01
Binary numbers
.1 1
+
10
Fractional part
of a number converted to binary
by x2
1. Multiply the fractional part of a number by the base
2
1.510
Discard that integer part
for the next iteration
0.5 x 2 =1.010
0.375 =
0.25 + 0.125
12
Conversion error
Rational numbers
Decimal-to-Binary Conversion
To be performed separately for integer and fractional parts
Continuous
division by 2
Continuous
multiplication by 2
Binary
Hexadecimal
10
11
100
101
110
111
1000
1001
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
Decimal
Binary
Hexadecimal
10
1010
11
1011
12
1100
13
1101
14
1110
15
1111
16
24
+ 23 +
20) 24 + 23 +
21
21
1 1 0 1 1 0 1 02 = (1101) 24 +(1010) 20
1 1 0 1 1 0 1 02 =
D 24 + A 20 = DA16
17
Hexadecimal numbers
with fractional parts
Binary arithmetic
11+10 = ?
There are 10 kinds of people:
1) Those who understand binary notation,
and
2) those who do not
19
Carries in addition
Borrows in subtraction
11
+ 10
101
x
Sum =0
Carry=1
x2
1
11
+
01
100
C1
Cin =
10
01
01
Difference =1,
Borrow =1
20
X
Y
COUT Sum
Two outputs
COUT
Sum
George Stibitz
(1904-1995)
Logical 1
13
2
Vdc
5
1
X
9
6
Logical 0
5
1
SUM
4
8
0 1
16
1
21
CARRYOUT
Carry-in
Xi
Yi
CIN
=
C C C
+ 3 2 1
X X X X
+ 3 2 1 0
Y3 Y2 Y1 Y0
C4 S3 S2 S1 S0
carry-out for digit 1=
= carry-in for digit 2
COUT=
Ci+1
Sum
Si
Ci
X
Y
BIN
BOUT Diff
Bin
BOUT
Diff
borrows
MULTIPLICATION
by Addition and LEFT SHIFT
P4
X 2 X1
Y1
X0
Y0
P2
P1
1 1 0
x
1 1
__________
1 1 1 0
Carry=
+ 1 1 0
____________
1 0 0 1 0
23
24
1 1.1
quotient
1 0 02
divisor
1 1 1 0. 2
100
1 1 0.
- 100
-
1 0. 0
10 0
0
dividend
Right shift
=division by 2
Division by 2 is equivalent to right
shift of all digits by one position
25
26
1s complement of N
2s complement of N = -N
01111111
+127 10000000
10000001
-127
01111110
+126 10000001
10000010
-126
+1
00000010
+2
111111101
11111110
-2
00000001
+1
111111110
11111111
-1
00000000
111111111
00000000
27
1s complement of N
N + 1s c. of N
=minus zero
0= 0 0 0
111
111
+1= 0 0 1
110
111
+2= 0 1 0
101
111
+3= 0 1 1
100
111
011
010
001
000
+2
+3
+1
-0
101
100
28
2s complements
1s complement of N
2s c. of N =
1s c. of N +1
0= 0 0 0
111
000
+1= 0 0 1
110
111 =-1
+2= 0 1 0
101
+3= 0 1 1
100
+1
110 =-2
011
101 =-3
010
001
100 =-4
000
The 2s complement system of
111
presentation of negative
110
-2
numbers has a single zero
101
-3
100
-4
+2
+3
+1
-1
101
100
29
Negative N
+0
000
-0
100
+1
001
-1
101
+2
010
-2
110
+3
011
-3
111
start
end
011 = +3
010 = +2
001 = +1
000 = 0
111 = -1
110 = -2
101 = -3
100 = -4
+1step
-3
in 3-digit presentation
8=23 = 10002 = 0
addition of +5
<=>
011
010
001
000
111
110
101
100
8 - 3 = +5
subtraction of 3 =
= 3 steps down from +2
+4steps
In 3-bit system 8=0, a number does not change if one adds 23 to31it
4-th bit
discarded
addition
0
-1
000
111
001 = 1
+1
111 = 7
-1
Positive N
Negative N
1000 = 0
0
0
000
-1=7
111
+1
001
-2=6
110
+2
010
-3=5
101
+3
011
-4=4
100
-2
-3
+1
001
010
110
101
+2
011
+3
100
-4
32
2s c. of N = 2n N
+
001
110
111
original number
1s c. of it (by digit inversion)
1s c. of N = 2n 1 N
all 1s -1
2s c. = 1s c. + 1
Positive N
Negative N
000
-0
111
001
-1
110
010
-2
101
011
-3
100
33
Examples:
A = 0011100
-A = 1100100
B = 0011110
-B = 1100010
C = 000001
- C = 111111
D = 100000
-D = 100000
34
+13 = 00001101
12+4+1 =13
Negative
result
00001001
+1 1 1 1 0 1 0 0
--------------------- Magnitude by 2s c.-ting
1 1 1 1 1 1 0 1 =>2s c. => 00000011 = 310
35
Summary
1. Digital systems operate with BINARY numbers and codes while designers work with their compact
representation, HEX numbers
2. Perform decimal-to-binary conversion separately for integer and fractional parts
- divide-by-2 the integer part
- multiply-by-2 the fractional part, the max error is 2 -n
3. Results of addition and subtraction differ in Carry and Borrow bits
4. Multiplication and division can be performed by successive addition and subtraction, respectively
(and shift)
5. 2s complement representation eliminates the need in separate hardware for subtraction, i.e.
subtraction is performed by addition of a negative number presented in the 2s complement form
6. 1s complement is obtained by inversion of all bits
7. 2s complement is obtained from 1s complement by addition of 1
36