IEEE-754浮点数如何工作 [英] how IEEE-754 floating point numbers work
问题描述
float i = 1.5
在二进制文件中,这个浮点数表示为:
$ b $ 0 01111111 10000000000000000000000
我把二进制代码分解为'signed','exponent'和'fraction'块。
我不明白这个代表的是1.5。
一旦你减去了偏差(127-127),指数就是0,隐含的前一个的分数部分是1.1。 p>
1.1如何通过nothing缩放到1.5 ???解决方案
首先是小数点(以10为底):643.72是:
$ ul $(6 * 10 <2> )+ (4 * 10 <1>)+
<3>(3 * 10 0 )+
(7 * 10 <-1> )+
<2>(2 * 10 <-2>)
或600 + 40 + 3 + 7/10 + 2/100。 其中2 0 是一个,而2 -1 是一半。 十进制小数点左边的数字有小数点左边的乘数1,10,100等,以及1/10,1/100,1/1000标题右(即,10 2,10 1,10 0,小数点10 -1,10 10, sup> -2 ,...)。 在base-2中,二进制点左边的数字有乘法器1,2,4 ,8,16等左转。右边的数字有乘数1 / 2,1 / 4,1 / 8,等等。右边的。
那是因为n 0 是alwa ys 1,n-1与1 / n相同(对于一个特定的情况),而n -m与m相同1 / n (更一般的情况)。
同样,二进制数字1.1是:
$ b $ ul
因此,例如,二进制数字
101.00101
| | | |
| | | + - 1/32
| | + --- 1/8
| + ------- 1
+ --------- 4
相当于:
4 + 1 + 1/8 + 1/32
$ c
$ b 或者:
$ $ p $ 5
5 -
32
Let's say I have this:
float i = 1.5
in binary, this float is represented as:
0 01111111 10000000000000000000000
I broke up the binary to represent the 'signed', 'exponent' and 'fraction' chunks.
What I don't understand is how this represents 1.5.
The exponent is 0 once you subtract the bias (127 - 127), and the fraction part with the implicit leading one is 1.1.
How does 1.1 scaled by nothing = 1.5???
Think first in terms of decimal (base 10): 643.72 is:
- (6 * 102) +
- (4 * 101) +
- (3 * 100) +
- (7 * 10-1) +
- (2 * 10-2)
or 600 + 40 + 3 + 7/10 + 2/100.
That's because n0 is always 1, n-1 is the same as 1/n (for a specific case) and n-m is identical to 1/nm (for more general case).
Similarly, the binary number 1.1 is:
- (1 * 20) +
- (1 * 2-1)
with 20 being one and 2-1 being one-half.
In decimal, the numbers to the left of the decimal point have multipliers 1, 10, 100 and so on heading left from the decimal point, and 1/10, 1/100, 1/1000 heading right (i.e., 102, 101, 100, decimal point, 10-1, 10-2, ...).
In base-2, the numbers to the left of the binary point have multipliers 1, 2, 4, 8, 16 and so on heading left. The numbers to the right have multipliers 1/2, 1/4, 1/8 and so on heading right.
So, for example, the binary number:
101.00101
| | | |
| | | +- 1/32
| | +--- 1/8
| +------- 1
+--------- 4
is equivalent to:
4 + 1 + 1/8 + 1/32
or:
5
5 --
32
这篇关于IEEE-754浮点数如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!