0% found this document useful (0 votes)
108 views23 pages

Floating Point Numbers

Here are the solutions to the homework problems: 1) 0101000000111111 Exponent = 32 Mantissa = 15 Decimal = 15 2) 0001101000000110 Exponent = 6 Mantissa = 0.75 Decimal = 0.75 3) 1101000000111111 Exponent = -32 (2s complement = -32) Mantissa = 15 (2s complement = 15) Decimal = -15 4) 1001101000000110 Exponent = 26 Mantissa = 11.5 Decimal = 11.5 5) For -15/32: Integer = 11111 Fraction = .011 (2s

Uploaded by

huhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views23 pages

Floating Point Numbers

Here are the solutions to the homework problems: 1) 0101000000111111 Exponent = 32 Mantissa = 15 Decimal = 15 2) 0001101000000110 Exponent = 6 Mantissa = 0.75 Decimal = 0.75 3) 1101000000111111 Exponent = -32 (2s complement = -32) Mantissa = 15 (2s complement = 15) Decimal = -15 4) 1001101000000110 Exponent = 26 Mantissa = 11.5 Decimal = 11.5 5) For -15/32: Integer = 11111 Fraction = .011 (2s

Uploaded by

huhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Learning Objectives

• 3.3.1f - Describe the nature and uses of floating point


form
• 3.3.1h - Convert a real number to floating point form
• Learn how to normalise a floating point binary
numbers
• Learn why we want to normalise floating point

1
Floating Point Denary
• Recall Mantissa and Exponent

1.637 x 105

Start with 1.637 Shift point 5 places to the right.

163700.

What base will we use


for binary?
Floating Point Binary
• Recall Mantissa and Exponent

0.10100111 x 25

Start with 0.10100111 Shift point 5 places to the right.

10100.111
Converting Binary
Floating Point to Decimal

10100.111 20 and 7/8


Floating Point Representation
2’s complement is
• Recall Mantissa and Exponent used for negatives

0 • 1 0 1 1 0 0 1 0 0 0 0 0 1 0 0
1. Markout Exponent, Mantissa, and Decimal 1. 0.101100100 000100

2. Sign Bit is Positive on exponent and 2. Positive Numbers


mantissa

3. Convert Exponent 3. +4

4. Positive exponent means shift decimal in 4. 01011.00100


mantissa +4 right

5. Convert to decimal 5. 8+2+1 + 1/8 = 11.125d


2’s
complement
is used Negative Exponent
1 • 1 0 0 1 1 0 0 0 0 1 1 1 1 0 0
1. Markout Exponent, Mantissa, and Decimal 1. 1.100110000 111100

2. Sign Bit is Negative on exponent and 2. Negative Numbers


mantissa means 2’s complement numbers

3. Convert Exponent From 2’s Complement 3. -000100 = -4


But Remember It’s Negative

4. Convert Mantissa From 2’s Complement 4. -0.011010000


But Remember It’s Negative

5. Shift decimal -4 places means left 5. -0.0000011010000

6. Convert to decimal, Remember it’s 6. -1/64 + 1/128 + 1/512 =


negative -0.025390625
1100111000001000 (6-bit exp)
1. Mark Out
1.100111000 | 001000
2. Determine Signs
Exponent is positive; Mantissa is negative
3. Convert Exp to decimal; Remember sign
Convert 2s complement +8
4. If mantissa is negative, convert it; Remember sign
Convert 2s complement  -0.011001000
5. Shift mantissa
-0.011001000  001100100.0
6. Convert mantissa; Remember sign
4+32+64 -100
8-bit mantissa, 4-bit exponent
Your Turn 2s complement, Normalised

1.001 0111 0100 -13.125

0.100 0000 1110 0.125

1.011 1111 0010 -2.03125

1.000 1100 0100 -14.5


Normalisation
.
10100 111

Move
That
Decimal
.
1 0100111
Big Problem
0.100000000 000010 0.100000000 x 22 2
0.010000000 000011 0.010000000 x 23 2
0.001000000 000100 0.001000000 x 24 2

If we let any number of leading 0s in If we have more than 1 way to


and adjust the exponent we get represent a number it reduces the
multiple ways to represent the same "pool" of possible numbers we can
number.  represent.

Normalisation is the way around this.


Another Big Problem
0.100000000 000010 0.100000000 x 22 2
Let’s add in some number of leading 0s and adjust the exponent.

0.000100000101  000101 We also have to drop the 101 off the


end because we don't have enough
bits to store it. 
0.000100000  000101
We've reduced the precision of our
number.

Normalisation is the way around this.


Normalisation
• Ensures only 1 way to represent each number
• Ensures maximum range available
• Normalised numbers always begin with two bits that
are different
• You may have to move the decimal yourself and
adjust the exponent accordingly.

Positive Numbers 0.1


Negative Numbers 1.0
Normalised
10 bit mantissa, 6 bit exponent
• Good (Normalised)
Normalised begin with
– 0.100110011 110001 different patterns
Remember, may need to
– 1.001100111 110010 change your exponent to
make it normalised

• Bad (Unnormalised)
– 0.001101001 100111
– 1.110001101 010011
Your Turn
• 0.001101001 100111
Exponent is negative, convert it back to decimal
011001 = 25 (negative)
Move decimal to normalised location
0.110100100
To get back to original location, I have to move decimal -2 places
-25 + -2 = -27 is the new exponent
011011  2s comp 100101
Float = 0.110100100 100101
Your Turn
• 1.110001101 010011
Exponent is positive, convert it back to decimal
010011 = 19 (positive)
Move decimal to normalised location
1.000110100
To get back to original location, I have to move decimal -2 places
19 + -2 = 17 is the new decimal
100010
Float = 1.000110100 100010
Converting Fractions
to Binary
Convert Fractions to Binary
• This is a simple algorithm for converting fractional parts of
numbers to binary
• Put the fraction into decimal format
• Multiply by 2
• If the whole number part of result is 0, then binary digit is 0; if
the whole number part of result is 1, then binary digit is 1
• Mod the result (take the fractional part only)
• Keep going until you get 0 as a result or fill all of your binary
digit slots
Example
• 15/32 = 0.46875 .01111
Multiply Result Binary
0.46875 x 2 0.93750 0
0.93750 x 2 1.8750 1
.8750 x 2 1.75 1
.75 x 2 1.5 1
.5 x 2 1.0 1

.011110 Fill in with following 0s to number of bits


you need
Converting Decimal to Binary
Floating Point
(The Whole Thing Together)
Given a Decimal Number
BinInteger = Convert integer part of number to binary
BinFraction = Convert fractional part of number to binary
If decimal number is negative
BinInteger = 2s complement of BinInteger
BinFraction = 2s complement of BinFraction
NonNormalFloat = write BinInteger + “.” + BinFraction
NormalFloat = Normalise NonNormalFloat
Exponent = Count decimal movement & determine sign
Convert Exponent to binary
If Exponent is negative
Exponent = 2s complement of Exponent
If NormalFloat has empty slots
Fill with 0s on right
If Exponent has empty slots
Fill with 0s if positive or 1s if negative on left
Answer = NormalFloat join Exponent
10-bit Mantissa
Full Example: -27.625 6-bit Exponent

0000011011
BinInteger = Convert integer part of number to binary
BinFraction = Convert fractional part of number to .101
binary
If decimal number is negative Yes
BinInteger = 2s complement of BinInteger 1111100101
BinFraction = 2s complement of BinFraction .011
1111100101.011
NonNormalFloat = write BinInteger + “.” + BinFraction
NormalFloat = Normalise NonNormalFloat 1.00101011
Exponent = Count decimal movement & determine sign +5
Convert Exponent to binary 101
If Exponent is negative
Exponent = 2s complement of Exponent
If NormalFloat has empty slots Yes
Fill with 0s on right 1.001010110
If Exponent has empty slots Yes
101000
Fill with 0s if positive or 1s if negative on left
Answer = NormalFloat join Exponent 1001010110101000
Homework
• Assume 6-bit exponent, 10-bit mantissa, 2s
complement, normalised form
• Convert to decimal
1. 0101000000111111
2. 0001101000000110
3. 1101000000111111
4. 1001101000000110
Homework
• Assume 10-bit mantissa, 6-bit exponent, 2s
complement.
• Convert to normalised floating point
1. 123
2. 0.1875
3. -15/32

You might also like