modified | title |
---|---|
2025-01-14 21:57:38 UTC |
Floating Point |
- Floating points provide accuracy of a greater range of values with a given number of bits
- Sign bit
- Mantissa
- Exponent
- If the Exponent is positive then the decimal place moves to the left and if the exponent is negative then the decimal place moves to the right
- Always involves a 'Sign Bit'
- Always uses Two's Compliment
-
Determine the Sign Bit:
- If the number is positive, the sign bit is
0
. - If the number is negative, the sign bit is
1
.
- If the number is positive, the sign bit is
-
Convert the Number to Binary:
- Convert the absolute value of the number to its binary form.
-
Normalize the Binary Number:
- Adjust the binary number so that it is in the form of
1.xxxxx * 2^n
. - Count the number of positions the decimal point has moved to determine the exponent
n
.
- Adjust the binary number so that it is in the form of
-
Calculate the Exponent:
- Add the bias to the exponent
n
. The bias is typically127
for single-precision floating point numbers. - Convert the biased exponent to binary.
- Add the bias to the exponent
-
Determine the Mantissa:
- The mantissa is the fractional part of the normalized binary number (excluding the leading
1
).
- The mantissa is the fractional part of the normalized binary number (excluding the leading
-
Combine the Components:
- Combine the sign bit, the exponent, and the mantissa to form the final floating point representation.
Example:
- Convert
-5.75
to floating point:- Sign bit:
1
(since the number is negative) - Binary:
5.75
in binary is101.11
- Normalize:
1.0111 * 2^2
- Exponent:
2 + 127 = 129
→10000001
in binary - Mantissa:
01110000000000000000000
- Final representation:
1 10000001 01110000000000000000000
- Sign bit: