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
Floating Point Denary 1.637 x 105 Recall Mantissa and Exponent Start with 1.637 Shift point 5 places to the right. 163700. What base will we use for binary?
Shift point 5 places to the right. 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 20 and 7/8 10100.111
Floating Point Representation 2’s complement is used for negatives Recall Mantissa and Exponent • 1 Markout Exponent, Mantissa, and Decimal Sign Bit is Positive on exponent and mantissa Convert Exponent Positive exponent means shift decimal in mantissa +4 right Convert to decimal 0.101100100 000100 Positive Numbers +4 01011.00100 8+2+1 + 1/8 = 11.125d
Negative Exponent 1 • 2’s complement is used Markout Exponent, Mantissa, and Decimal Sign Bit is Negative on exponent and mantissa means 2’s complement numbers Convert Exponent From 2’s Complement But Remember It’s Negative Convert Mantissa From 2’s Complement But Remember It’s Negative Shift decimal -4 places means left Convert to decimal, Remember it’s negative 1.100110000 111100 Negative Numbers -000100 = -4 -0.011010000 -0.0000011010000 -1/64 + 1/128 + 1/512 = -0.025390625
1100111000001000 (6-bit exp) Mark Out Determine Signs 1.100111000 | 001000 Determine Signs Exponent is positive; Mantissa is negative Convert Exp to decimal; Remember sign Convert 2s complement +8 If mantissa is negative, convert it; Remember sign Convert 2s complement -0.011001000 Shift mantissa -0.011001000 001100100.0 Convert mantissa; Remember sign 4+32+64 -100
Your Turn 8-bit mantissa, 4-bit exponent 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 Normalisation is the way around this. 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 and adjust the exponent we get multiple ways to represent the same number. If we have more than 1 way to represent a number it reduces the "pool" of possible numbers we can represent. Normalisation is the way around this.
Another Big Problem Normalisation is the way around this. 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 Good (Normalised) Bad (Unnormalised) 0.100110011 110001 0.100110011 110001 1.001100111 110010 Bad (Unnormalised) 0.001101001 100111 1.110001101 010011 10 bit mantissa, 6 bit exponent Normalised begin with different patterns Remember, may need to change your exponent to make it normalised
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
.011110 Fill in with following 0s to number of bits you need Example 15/32 = 0.46875 .01111 Multiply Result Binary 0.46875 x 2 0.93750 0.93750 x 2 1.8750 1 .8750 x 2 1.75 .75 x 2 1.5 .5 x 2 1.0 .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
Full Example: -27.625 10-bit Mantissa 6-bit Exponent 0000011011 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 0000011011 .101 Yes 1111100101 .011 1111100101.011 1.00101011 +5 101 1.001010110 101000 1001010110101000
Homework Assume 6-bit exponent, 10-bit mantissa, 2s complement, normalised form Convert to decimal 0101000000111111 0001101000000110 1101000000111111 1001101000000110
Homework Assume 10-bit mantissa, 6-bit exponent, 2s complement. Convert to normalised floating point 123 0.1875 -15/32