Professional Documents
Culture Documents
25 + 22 = (24 + 21)*21
2
Power-of-2 multiply and division
23 + 20 = (24 + 21)/21
3
Power-of-2 multiply and division
4
Fractional binary numbers
Example: What’s the decimal value corresponding to 10.012. Show
your steps.
2i
2i-1
4
2
•••
1
5
2-j
Fractional binary numbers
Example: What’s the decimal value corresponding to 10.012. Show
your steps.
6
Fractional binary numbers
Example: Find the binary representation for 6.7510. Show your
steps.
2i
2i-1
4
2
•••
1
2-j 7
Fractional binary numbers
Example: Find the binary representation for 6.7510. Show your
steps.
610 = 4 + 2
= 22+ 21
= 1102
6.7510 = 110.112
8
Fractional binary conversion -- Algorithm
Algorithm to find binary representation for 2.62510.
2.62510 = 210 + 0.62510
The fractional part: 1) multiply by 2 and keep record of the resulting integer and
fractional part. 2) Repeat multiplying the fractional part by 2 until you get a
resulting fractional part equal to zero. 3) Then just assemble the integeral parts of
the results of each multiplication
0.625*21 = 1.2510 (1) 1 becomes 1st digit after the decimal point
0.25*21 = 0.510 (0) 0 becomes 2nd digit after the decimal point
0.5*21 =1.010. (1) 1 becomes 3rd digit after the decimal point
à 0.62510 = 0.1012
2.62510 = 10.1012 9
Fractional binary numbers
Example: Convert 6.7510 to binary use the algorithm introduced in
the previous slide. Show your steps.
6.7510 = 110.112
10
Fractional binary conversion -- Algorithm
Algorithm explanation:
0.62510 = 0.xyz2
= x*2-1 + y*2-2 + z* 2-3
0.62510 = 0.1012 11
0 000 0000 0 0000 0000 0000 0000 0000 000 0
s exp frac
Minimum
0 000 0000 0 0000 0000 0000 0000 0000 001 denormalized
exp = value
0000 0000
and s exp frac
…
frac ≠ Maximum
0000 … 0000 0 000 0000 0 1111 1111 1111 1111 1111 111 denormalized
value
s exp frac
In the
Minimum
0 000 0000 1 0000 0000 0000 0000 0000 000 Normalized value
positive
exp ≠
0000 0000
range
and
s exp frac
…
exp ≠ Maximum
1111 1111 0 111 1111 0 1111 1111 1111 1111 1111 111 Normalized value
s exp frac
0 111 1111 1 0000 0000 0000 0000 0000 000 +∞
s exp frac
0 111 1111 1 Any non-zero bit sequence NaN
s exp frac 12
Floating point numbers
13
Floating point numbers
Example: what does 0x0FF00000 represent: normalized value, denormalized
value, infinity, NaN? Explain why.
14
Exercise
15
Power-of-2 multiply and divide
Ex. 1: what will be the results for 3510 << 1, 3510 >> 2? Represent the
results in both binary and decimal format. Show your steps.
Hint: first translate 3510 into binary format, then apply the power-of-2
multiply/divide. You will get the binary result, then translate it into
decimal.
16
Fractional binary numbers
Ex. 2: What’s the decimal value corresponding to 111.1012. Show
your steps.
2i
2i-1
4
2
•••
1
17
2-j
Fractional binary numbers
Ex. 3: Find the binary representation for 30.87510. Show your steps.
2i
2i-1
4
2
•••
1
2-j 18
Fractional binary numbers
Ex. 4: prove that 1.0112 << 1 = 10.112. Show your steps.
2i
2i-1
4
2
•••
1
19
2-j
Fractional binary numbers
Ex. 5: prove that 101.12 >> 1 = 10.112. Show your steps.
2i
2i-1
4
2
•••
1
20
2-j
Fractional binary numbers
Ex. 6: what is your observation about left or right shifted operation
for fractional binary numbers, based on the two examples seen
before, namely 1.0112 << 1 = 10.112 and 101.12 >> 1 = 10.112.
21
Fractional binary numbers
Ex. 7: Convert 95.12510 to binary use the algorithm introduced in
the first part. Show your steps. i
2
2i-1
4
2
•••
1
2-j
22
0 000 0000 0 0000 0000 0000 0000 0000 000 0
s exp frac
Minimum
0 000 0000 0 0000 0000 0000 0000 0000 001 denormalized
exp = value
0000 0000
and s exp frac
…
frac ≠ Maximum
0000 … 0000 0 000 0000 0 1111 1111 1111 1111 1111 111 denormalized
value
s exp frac
In the
Minimum
0 000 0000 1 0000 0000 0000 0000 0000 000 Normalized value
positive
exp ≠
0000 0000
range
and
s exp frac
…
exp ≠ Maximum
1111 1111 0 111 1111 0 1111 1111 1111 1111 1111 111 Normalized value
s exp frac
0 111 1111 1 0000 0000 0000 0000 0000 000 +∞
s exp frac
0 111 1111 1 Any non-zero bit sequence NaN
s exp frac 23
Floating point numbers
24
Solutions
25
Power-of-2 multiply and divide
Ex. 1: what will be the results for 3510 << 1, 3510 >> 2? Represent the
results in both binary and decimal format.
Answer:
3510 = 3210 + 310 = 0010 00112
26
Fractional binary numbers
Ex. 2: What’s the decimal value corresponding to 111.1012. Show
your steps.
27
Fractional binary numbers
Ex. 3: Find the binary representation for 30.87510. Show your steps.
3010 = 16 + 8 + 4 + 2
= 24 + 23 + 22+ 21
= 111102
28
Fractional binary numbers
Ex. 4: prove that 1.0112 << 1 = 10.112. Show your steps.
method 1:
1.0112 = 1.37510
1.0112 << 1 = 1.37510 * 21 = 2.7510 = 10.112
method 2:
1.0112 << 1 = (1*20 + 0*2-1 + 1*2-2 + 1* 2-3) * 21
= 1*21 + 0*20 + 1*2-1 + 1* 2-2
= 10.112
29
Fractional binary numbers
Ex. 5: prove that 101.12 >> 1 = 10.112. Show your steps.
method 1:
101.12 = 5.510
101.12 >> 1 = 5.510 / 21 = 2.7510 = 10.112
method 2:
101.12 >> 1 = (1*22 + 0*21 + 1*20 + 1* 2-1) / 21
= 1*21 + 0*20 + 1*2-1 + 1* 2-2
= 10.112
30
Fractional binary numbers
Ex. 6: what is your observation about left or right shifted operation
for fractional binary numbers, based on the two examples seen
before, namely 1.0112 << 1 = 10.112 and 101.12 >> 1 = 10.112.
left shifted op. : move the binary point to the right by N positions;
right shifted op. : move the binary point to the left by N positions
31
Fractional binary numbers
Ex. 7: Convert 95.12510 to binary use the algorithm introduced in
the first part. Show your steps.
9510 = 64 + 31
= 26 + 24 + 23 + 22 + 21 + 20
= 101 11112
0.12510 * 2 = 0.2510 (0)
0.2510 * 2 = 0.510 (0)
0.510 * 2 = 1.010 (1)
à 0.12510 = 0.0012
95.12510 = 1011111.0012
32
Floating point numbers
Ex. 8: Among the following numbers represented in hexadecimal, which is
or are NaN? Explain why?
a) 0x7F800000 +∞
b) 0x7FA00000 7F800000 0 111 1111 1 0000 0000 0000 0000 0000 000