What about signed fixed point?
■ Could also have a signed-magnitude fixed-point number
◆ MSB represents positive (0) or negative (1) ■ It is possible to have a fixed-point two’s
complement number
◆ Would it be any different?
CMPE12 – Spring 2021
1
How does arithmetic work with fixed point?
■ Addition is the same!
◆ If the two numbers have the same scale
■ Subtraction is the same!
◆ If the two numbers have the same scale
■ Multiplication is the same!
◆ But it must keep the correct number of fraction bits in
the product…
◆ Both numbers are “scaled” so the result has double the “scale”
CMPE12 – Spring 2021
2
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
■ What is the result?
CMPE12 – Spring 2021
3
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
0011.1100 = 1+2+1⁄2 +1⁄4
◆
■ What is the result?
CMPE12 – Spring 2021
4
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
0011.1100 = 1+2+1⁄2 +1⁄4 = 3.75
◆
■ What is the result? CMPE12 – Spring 2021
5
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
0011.1100 = 1+2+1⁄2 +1⁄4 = 3.75
0000.0110 = 0 + 1⁄4 +1⁄8 = .375
■ What is the result?
◆
CMPE12 – Spring 2021
6
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
0011.1100 = 1+2+1⁄2 +1⁄4 = 3.75
0000.0110 = 0 + 1⁄4 +1⁄8 = .375
■ What is the result? 0011.1100
+ 0000.0110 100.0010
◆
CMPE12 – Spring 2021
7
Example adding two fixed point numbers
■ 0011.1100 + 0000.0110
■ What are the values?
0011.1100 = 1+2+1⁄2 +1⁄4 = 3.75
0000.0110 = 0 + 1⁄4 +1⁄8 = .375
■ What is the result? 0011.1100
+ 0000.0110
100.0010 = 4 + 1⁄8 = 4.125
◆
CMPE12 – Spring 2021
8
Floating Point Numbers
Consider: A x 10B, where A is one digit
A B
0 any 1..9 0 1..9 1 1..9 2
1..9 -1 1..9 -2
A x 10B
0
1 .. 9
10 .. 90 100 .. 900
0.1 .. 0.9 0.01 .. 0.09
How to do scientific notation in binary? Standard: IEEE 754 Floating-Point
CMPE12 – Spring 2021
9
Real numbers
■ Our decimal system handles non-integer real numbers by adding yet another symbol – the decimal point (.) to make a fixed point notation:
◆ e.g. 3,456.78 = 3*103 + 4*102 + 5*101 + 6*100 + 7*10-1 + 8.10-2
■ The floating point, or scientific, notation allows us to represent very large and very small numbers (integer or real), with as much or as little precision as needed:
◆ Unit of electric charge e = 1.602 176 462 * 10-19 Coul. ◆ Volume of universe = 1 * 1085 cm3
★ the two components of these numbers are called the mantissa and the
CMPE12 – Spring 2021
exponent
10
Real numbers in floating point
■
We mimic the decimal floating point notation to create a “hybrid” binary floating point number:
◆ We first use a “binary point” to separate whole numbers from fractional numbers to make a fixed point notation:
★ e.g. 00011001.110 = 1*24 + 1*23 + 1*20 + 1*2-1 + 1*2-2 => 25.75 (2-1 = 0.5 and 2-2 = 0.25, etc.)
◆ We then “float” the binary point: ★ 00011001.110=>1.1001110×24
mantissa = 1.1001110, exponent = 4
◆ Now we have to express this without the extra symbols ( x, 2, . ) ★ byconvention,wedividetheavailablebitsintothreefields:
sign, mantissa, exponent CMPE12 – Spring 2021
11
IEEE-754 fp numbers Single Precision
23 bits
N = (-1)s x 1.fraction x 2(biased exp. – 127)
32 bits: 1 8 bits
s
biased exp.
fraction
■ Sign: 1 bit
■ Mantissa: 23 bits
◆ We“normalize”themantissabydroppingtheleading1andrecordingonly its fractional part
■ Exponent: 8 bits
◆ Inordertohandleboth+veand-veexponents,weadd127totheactual
exponent to create a “biased exponent”:
★ 2-127 => biased exponent = 0000 0000 (= 0)
★ 20 => biased exponent = 0111 1111 (= 127)
★ 2+127=>biasedexponent=11111110(=254)
CMPE12 – Spring 2021
12
IEEE-754 fp numbers
■ Example:
★ 25.75 => 00011001.110 => 1.1001110 x 24
★ signbit=0(+ve)
★ normalized mantissa (fraction) = (1.)100 1110 0000 0000 0000 0000
★ biased exponent = 4 + 127 = 131 => 1000 0011
★ so 25.75 => 0 1000 0011 100 1110 0000 0000 0000 0000
=> 0x41CE0000
CMPE12 – Spring 2021
13
How to convert 64.2 into IEEE SP
■ Get a binary representation for 64.2
◆ Binary of left of radix/decimal point is: 1000000
◆ Binary of right of radix/decimal:
★ Successively multiply value by 2 and compare to 1 • 0.2×2=0.4lessthan1so… 0
• 0.4×2=0.8lessthan1so… 0
• 0.8×2=1.6g.t.1so… 1
• 0.6×2=1.2g.t.1so… 1 • 0.2×2=0.4 0 • 0.4×2=0.8 0 • 0.8×2=1.6 1 • 0.6×2=1.2 1
CMPE12 – Spring 2021
14
Quiz 2 is available on Canvas right now!
CMPE12 – Spring 2021
15
(continued)
◆ Binary for .2: .0011 0011 0011 0011
◆ 64.2 is: 1000000.0011001100110011…
■ Normalize binary form
◆ Produces: 1.0000000011 X 26
CMPE12 – Spring 2021
16
(continued)
■ 3. Turn true exponent into bias 127 ◆ E=6+127=133=10000101
■ 4. Put it together:
◆ 23-bit F is: (1.)0000000011 0011 0011 0011 0
■ SEFis: ◆ S=0
◆ E = 10000101
◆ F = 00000000110011001100110
■ In hex:
◆ 0x42806666
CMPE12 – Spring 2021
0
100 0010 1
000 0000 0110 0110 0110 0110
17
Convert IEEE SP to real
■ What is the decimal value for this SP FP number 0xC228 0000?
◆ Convert to binary 1
100 0010 0
010 1000 0000 0000 0000 0000
◆ Break into S, E, F:
◆ E is 10000100 = 132 decimal: 132 – 127= 5
◆ F is (1.)0101000…
◆ Move decimal over 5: 101010.000… ◆ SEFis-42!
CMPE12 – Spring 2021
18
Convert IEEE SP to Real
■ 0x3F800000
CMPE12 – Spring 2021
19
Convert IEEE SP to Real
■ 0x3F800000
0011 1111 1000 0000 0000 0000 0000 0000
CMPE12 – Spring 2021
20
Convert IEEE SP to Real
■ 0x3F800000
0
011 1111 1
S=0
000 0000 0000 0000 0000 0000
E = 0111 1111 = 127 –
F = 1.0
127
0x3F8 = 1 in single precision floating point CMPE12 – Spring 2021
21
Take Home Practice
■ What is 47.62510 in SP FP format?
■ What is 0x44ed8000 as real number?
CMPE12 – Spring 2021
22
Check your Practice
■ http://www.h-schmidt.net/FloatConverter/IEEE754.html
CMPE12 – Spring 2021
23
IEEE-754 Double Precision
■ Double precision (64 bit) floating point 64 bits: 1 11 bits 52 bits
N = (-1)s x 1.fraction x 2(biased exp. – 1023)
biased
exp.
fraction
CMPE12 – Spring 2021
s
24
How to represent 0, NaN, +/- Infinity?
◆ Values represented by convention:
◆ Infinity (+ and -): exponent = 255 (1111 1111) and
hidden 1)
fraction = 0
◆ NaN (not a number): exponent = 255 and fraction ≠ 0
◆ Zero (0): exponent = 0 and fraction = 0
★ Note: exponent = 0 => fraction is de-normalized (i.e. no
CMPE12 – Spring 2021
25