Notes From CS Undergrad Courses FSU
This project is maintained by awa03
How do we represent numbers such as 5.75 in binary In general to represent a real number in binary
$5_{10} = 101_2$ $0.75_{10} = 0.11_2$ $5.75_{10} = 101.11_2$
It is not however stored in this manner, but this can be used if done on paper or just for example.
You must multiply by two and collect the whole number parts, as opposed to dividing by 2 and collecting the remainders.
$4.25_{10}$ $4_{10} = 100_2$
Fractional Part | Multiply by 2, collect the whole |
---|---|
$0.25 * 2$ | 0.5- bit is 0, remainder is 0.5 |
$0.5*2$ | 1- bit is 1, remainder is 0. stop |
Write In the FORWARD direction $4.25_{10} = 100.01_2$
$12.375_{10}$ $12_{10} = 1100_2$
Fractional Part | Multiply by 2, collect the whole |
---|---|
$.375 * 2$ | .75 -> 0 |
$.75 * 2$ | 1.5 -> 1 |
$.5 * 2$ | 1. Stop |
$12.375_{10} = 1100.011_2$
3.10000000012143
for the value 3.1
For other Conversion View [[Binary Number Systems]] & [[Binary Arithmetic]]The formula for the normalized notation is shown below: $$1.x_2 * 2^y$$ We must because of limited bit storage weigh the trade-off of precision and size.
For Single Precision:
Bits | 31 (1 bit) | 30-23 (8bits) | 22-0 (23 bits) |
---|---|---|---|
Purpose | Sign | Exponent (biased) | Mantissa |
Mantissa is every number that follows the decimal point in the normalized notation
The value of a number in IEEE 754 single precision is thus: $$(-1)^{Sign} * x(1+0.Mantissa)*2^{(Exponent-127)}$$
Bits | 63 (1bit) | 62-52 (11 bits) | 51-0 (52 bits) |
---|---|---|---|
Purpose | Sign | Exponent (biased) | Mantissa |
Overflow/underflow happens when a number is outside the range of a particular representation
The mantissa can be adjusted with the exponent for loss of precision, or might result in a denormalized number Note that arithmetic operations can result in overflow/underflow
Procedure for converting decimals to float