Beruflich Dokumente
Kultur Dokumente
Computer Arithmetic
Part II: Integer Arithmetic & Floating Point
Integer Representation
Unsigned integer
Signed integer -> 2s complement
Integer Arithmetic
Addition/subtraction
Unsigned integer multiplication
Possible solution
Convert both multiplier and multiplicand to positive numbers, perform
unsigned integer multiplication, and then take the 2s complement of
the result if signs of the two original numbers differed
= 11100100 11111001
= 11101011(2110)
2 + 21 + 22 + + 2 = 2+1 2
A,M,Q: n-bits
Q-1: 1-bit, used to hold
previous LSB of multiplier
Product: A,Q
Arithmetic Shift
Shift operation that
preserves the sign bit
e.g. X = 11001101
Arithmetic shift right:
1 1 0 0 1 1 0 1
1 1 1 0 0 1 1 0
8
Booths Algorithmcntd
= +
Unsigned division
e.g. 1001/0010
0 01
0010 1001 0010 1001 0010 1001
10
00
0100 010
0010 1001 0010
10 1001
10
0001 000
Q. Compute 1011/0011 12
Integer Divisioncntd
13
Integer Divisioncntd
Q. Compute 1001/0010
A Q M Initial
0000 1001 0010 Values
Remainder
e.g. 12.25
Integer Decimal Fractional
Part (radix) Part
Point
Can be represented using:
Fixed-point representation
Floating-point representation
Zelalem Birhanu, AAiT 17
Fixed-point representation
. 0.125 = 0000.0010 = 23
Zelalem Birhanu, AAiT 18
Fixed-point representationcntd
Advantage
Integer representation is fixed-point representation with the
binary point positioned to the far right
Therefore, hardware for integer arithmetic can be reused for
fixed-point arithmetic
Drawback
Loss of range and precision
For the previous example the fractional part is only precise to
multiples of 0.0625 (e.g. can not represent 0.1)
Increase precision=>lose range, Increase range=>lose
precision
(Very large numbers and very small fractions can not be
represented)
Zelalem Birhanu, AAiT 19
Floating-point
Normalized numbers
The MSB of the significand is 1, the binary point comes
after the MSB
1. 2 = 0 1
e.g. the normalized form of 0.110 25 is 1.10 24
2
Only need to represent sign, signifiand and
exponent
IEEE 754
32-bits (single precision )
Sign bit 8 bits 23 bits
Exponent
8-bits (can be positive or negative)
Uses biased base 127 encoding (-127 to 128)
Add 127 to the exponent value to encode
-127 00000000 1 10000000
-126 00000001 2 10000001
0 01111111 128 11111111
How to represent 0
Exponent: -127 (all zeros), Fraction:0 (all zeros), sign: + or -
Zelalem Birhanu, AAiT 24
IEEE 754cntd
Example
Find the IEEE754 representation of 10.62510
. To binary . [ ]
.
Sign bit: 0
Exponent: 3+127=130=10000010
Fraction: 01010100000000000000000
0 10000010 01010100000000000000000
25
IEEE 754cntd
Exercise
Find the IEEE754 representation of 7.7510
. To binary . [ ]
.
Sign bit: 1
Exponent: 2+127=129=10000001
Fraction: 11110000000000000000000
1 10000001 11110000000000000000000
26
IEEE 754cntd
Exercise
What is the value (in decimal) of the following IEEE 754
floating point encoded number?
1 01111110 01000000000000000000000
Sign: Negative
Exponent:126-127 = -1
Significand:1.01
. = + = .
Range
32-bits -----1.18 1038 3.4 1038
64-bits -----2.23 10308 1.80 10308
Floating-point arithmetic