Overflow in Addition
■ Unsigned: When there is a carry out of the
MSB
1000 (8) +1001 (9)
1 0001 (1)
CMPE12 – Spring 2021
1
Overflow in Addition
■ 2’s complement: When the signs of the addends are the same, but the sign of the result is different
■ Adding 2 numbers of opposite signs never overflows.
0011 (3) + 0110 (6)
1001 (-7)
CMPE12 – Spring 2021
2
■ End of Midterm Coverage!
■ Quiz2 on 2/11/21 (10-15 mins)
■ Same format as Quiz1
■ Will cover till Midterm
■ Will not provide solutions for sample midterms
■ May discuss possible solutions amongst yourselves
■ Please attend more TA Office hours!
■ TAs have reported a sharp decline in attendance
CMPE12 – Spring 2021
3
Floating Point, FP Addition, FP Multiplication
(Unsigned) Fixed Point Numbers
■ With binary integers, we assume each position is a power of the base 2
◆ … 8’s, 4’s, 2’s, 1’s
◆ This is actually: …23, 22, 21, 20
■ What if we extend this with a negative power?
◆ 2-1, 2-2, 2-3, etc.
★ Negative exponent means it is denominator ★ 1⁄2, 1⁄4, 1⁄8, etc.
◆ 0.5’s, 0.25’s, 0.125’s, etc. CMPE12 – Spring 2021
5
Fixed Point Example 1
■ Convert to ◆ 12.75
CMPE12 – Spring 2021
a 4+4 bit fixed point number
6
Fixed Point Example 1
■ Convert to a 4+4 bit fixed point number
◆ ◆
? ? ? ?. ? ? ? ?
3 2 1 0. -1 -2 -3 -4
◆ 0.75=3⁄4=1⁄2+1⁄4 = .11
CMPE12 – Spring 2021
7
Fixed Point Example 1
■ Convert to ◆ 12=8+ = 11
CMPE12 – Spring 2021
a 4+4 bit fixed point number 4
00
8
Alternative way for finding out Binary of Fractions from a given Decimal value
■
■
Split the value into 2 parts: Integer part + Fractional part
Find the binary representation of
the integral part by repeatedly divide the value by 2 (to obtain the powers of 2n) (Already discussed in previous lectures)
Find the binary representation of
the fractional part by repeatedly multiply the value by 2 (to obtain the powers of 2-n)
■
CMPE12 – Spring 2021
9
Fixed Point Example 1:Alternative solution
■ Convert to a 4+4 bit fixed point number ◆ 12=8+4=11002
CMPE12 – Spring 2021 10
Fixed Point Example 2
■ Given 4+4 bit fixed point number, what is the decimal value?
◆ 0110.1010 CMPE12 – Spring 2021
11
Fixed Point Example 2
■ Given 4+4 bit fixed point number, what is the decimal value?
◆ 0110.1010=4+2+1⁄2+1⁄8 CMPE12 – Spring 2021
12
Fixed Point Example 2
■ Given 4+4 bit fixed point number, what is the decimal value?
◆ 0110.1010=4+2+1⁄2+1⁄8
= 6.625
CMPE12 – Spring 2021
13
(Unsigned) Fixed Point Precision
■ This assumes that the fraction point begins at a fixed bit location
◆ Example, 32-bit number, 8-bits decimal ★ 24 bits are used for the integer part
★ 8 bits are used for the decimal part
◆ You can think of each number as multiplied by a scale (28), shifts left 8 bits
■ What is the most accurate you can represent this fixed-point number(precision)?
◆ Example, 2-8 = 1/256 = 0.00390625 CMPE12 – Spring 2021
14
Repeating Fractions
■ Convert to ◆ 5.2
CMPE12 – Spring 2021
a 4+4 bit fixed point number
15
Repeating Fractions
■ Convert to ◆ 5=101
CMPE12 – Spring 2021
a 4+4 bit fixed point number
16
Repeating Fractions
■ Convert to a 4+4 bit fixed point number ◆ .2 = ????
1⁄2 = 0.5
1⁄4 = 0.25
1⁄8 = 0.125 1/16 = 0.0625
CMPE12 – Spring 2021
17
Repeating Fractions
■ Convert to a 4+4 bit fixed point number ◆ .2=???
CMPE12 – Spring 2021 18
Repeating Fractions
■
■
■ ■
■ ■
We saw that 0.210 cannot be exactly expressed in 4+4 fixed point since we will lose precision
So what is the most accurate we can represent it then in binary 4+4 ?
We know for certain, .00112 =0.187510< 0.210
Next largest possible binary number in 4+4 is .0011+ .0001 =0.0100= 0.2510
But 0.2-0.1875 < 0.25 – 0.2
Thus 0.0011 is the closest we can accurately convey 0.210 in binary 4+4
Therefore, 5.2 CMPE12 – Spring 2021
10
= 0101.0011 in 4+4
■
19
Repeating Fractions
■ Convert to ◆ 5.2≈01
CMPE12 – Spring 2021
a 4+4 bit fixed point number 01.0011
20
(Unsigned) Fixed Point Range
■ Consider again this 24 + 8 bit fixed point number.
■ What is the maximum value?
◆ All 1’s for integer, all 1’s for fraction ◆ 223 <– >2-8
■ What is the minimum value? ◆0
CMPE12 – Spring 2021
21