Difference between revisions of "Floating Point Numbers - Yr 2 Only"
(→Converting from Denary to Binary) |
(→Examples) |
||
Line 36: | Line 36: | ||
# Add 0’s to the mantissa if necessary (to give 10 bits in this case) | # Add 0’s to the mantissa if necessary (to give 10 bits in this case) | ||
− | === | + | ===Example 1=== |
Convert 123.5 to floating point form | Convert 123.5 to floating point form | ||
Line 47: | Line 47: | ||
Answer = 0111101110 000111 | Answer = 0111101110 000111 | ||
+ | |||
+ | ===Example 2=== | ||
+ | Convert 0.1875 to floating point form | ||
+ | |||
+ | # Convert number (0.1875) to pure binary = 0.0011 | ||
+ | # Normalise mantissa = 0.11 | ||
+ | # (Number not negative) | ||
+ | # The point has moved 2 places right, so exponent = - 2 | ||
+ | # Convert exponent to twos complement binary = 111110 | ||
+ | # Add 0’s to the mantissa = 0.110000000 | ||
+ | |||
+ | Answer = 0110000000 111110 | ||
+ | |||
+ | ===Example 3=== | ||
+ | Convert -0.375 to floating point form | ||
+ | |||
+ | # Convert number (-0.375) to pure binary = - 0.011 | ||
+ | # Normalise mantissa = - 0.11 | ||
+ | # Number negative so find twos complement = 1.01 | ||
+ | # The point has moved 1 place right, so exponent = - 1 | ||
+ | # Convert exponent to twos complement binary = 111111 | ||
+ | #Add 0’s to the mantissa = 1.010000000 | ||
+ | |||
+ | Answer = 1010000000 111111 |
Revision as of 12:51, 16 June 2017
Floating point numbers are a method of dynamic binary numerical representation, allowing for a customizable range and accuracy using the same number of digits. Floating point consists of 2 parts, a mantissa which contains the binary value of the represented number, and the exponent which shifts the decimal point according to the size of the number. For a floating point number to be normalized and make the best use of available memory, it must begin with "0.1" for a positive number and "1.0" for a negative number. Any deviation with this could be a waste of bits, as the same number could be represented with a smaller mantissa.
For example, the number 32 could be represented by a floating point number with an 8 bit mantissa and a 5 bit exponent.
The mantissa would be as follows: 0.1000000
The exponent must shift the decimal point to shift 1 into the value of 32, it must therefore have a value of 6: 00110
Contents
Converting from Binary to Denary
- Write down the mantissa, with the point inserted after the sign bit. (Miss off trailing 0’s)
- If the mantissa is negative (sign bit = 1) then
- find the twos complement of the mantissa
- If the exponent is negative (sign bit = 1) then
- find the twos complement of the exponent
- Calculate the value of the exponent in denary
- If the exponent is positive then
- move the point in the mantissa to the right the number of places given by the exponent
- else {if the exponent is negative}
- move the point in the mantissa to the left the number of places given by the exponent
- Convert the mantissa to denary to obtain the answer
Converting from Denary to Binary
- Convert the denary number to an unsigned binary number (the mantissa)
- Normalise this (move the point to in front of the leading 1)
- If the number is negative then
- represent it as its twos complement equivalent
- Count the number of places the point has been moved to give exponent
- If point moved left then
- exponent is positive
- else {if point moved right}
- exponent is negative
- Convert exponent to twos complement binary (6-bits in this case)
- Add 0’s to the mantissa if necessary (to give 10 bits in this case)
Example 1
Convert 123.5 to floating point form
- Convert number (123.5) to pure binary = 1111011.1
- Normalise mantissa = 0.11110111
- (Number not negative)
- The point has moved 7 places left, so exponent = 7
- Convert exponent to twos complement binary = 000111
- Add 0’s to the mantissa = 0.111101110
Answer = 0111101110 000111
Example 2
Convert 0.1875 to floating point form
- Convert number (0.1875) to pure binary = 0.0011
- Normalise mantissa = 0.11
- (Number not negative)
- The point has moved 2 places right, so exponent = - 2
- Convert exponent to twos complement binary = 111110
- Add 0’s to the mantissa = 0.110000000
Answer = 0110000000 111110
Example 3
Convert -0.375 to floating point form
- Convert number (-0.375) to pure binary = - 0.011
- Normalise mantissa = - 0.11
- Number negative so find twos complement = 1.01
- The point has moved 1 place right, so exponent = - 1
- Convert exponent to twos complement binary = 111111
- Add 0’s to the mantissa = 1.010000000
Answer = 1010000000 111111