IEEE754 单精度浮点数

IEEE 754

IEEE754 将数字表示成形如

$$Z=(-1)^s \times M \times 2^E$$

• 符号位s由一位二进制表示，1表示负数，0表示正数
• 有效数（尾数）M 由23位二进制表示
• 指数E由8位二进制移码表示

31          22                           0
|________________________________________|
|s|   c    |          f                  |
------------------------------------------
|      |
30    23


IEEE754 规定位数应该化为 1.f 的形式, 第一位由于必定为1, 略去不计。

栗子-3125.97

$log_210 = 3.322$ , 十进制转换2进制时小数应当记录7位。

$3125.97_{(10)} = 110000110101.1111100_{(2)} = 1.100001101011111100_{(2)} \times 2^{11}$

100 0011 0101 1111 1000 0000

11 转化为8位2进制移码。
$C = c + B = 11_{(10)} + 127_{(10)} = 138 = 1000 1010_{(2)}$

Z = 1100 0101 0100 0011 0101 1111 1000 0000

s = 1
c = 1000 1010
f = 100 0011 0101 1111 1000 0000


表示值

Name c f Z

Notes:

• 8位移码表示的指数中，偏移B=127
• c = e+B , 其中c为二进制移码表示的指数，e为二进制原码表示的指数
• 后两种特殊情况中，c=2B+1 即c=255, 取全1
• 非规约形式是为了表示绝对值非常接近0的数，非规约形式由于实际指数固定，在其表示范围内精度保持不变。

范围

23位2进制尾数表示范围是 $[0, 2^{23}]$

[-126,127] c = e+127
e = -126 c = 0

[-126,127]

c = e + 127, 即 [1,254]

$\pm (2-2^{-23}) \times 2^{127}$

$\pm 2^{-126}$

$\pm (1-2^{-23} \times 2^{-126})$

$\pm 2^{-23} \times 2^{-126}$

Nov 25, 2020

the comment system on this blog works via email. The button

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as
anonymous
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.


>> SEND COMMENT <<

Fun with Image Maps and SVGs via benji February 20, 2024

Over the past few weeks I've been playing around with making some images on my website interactive. My "informatics" class in high school taught us some basic HTML. By basic I mean in notepad and writing everything by hand, saving to a...

Goblin Week 2024 via Helvetica Blanc January 26, 2024

It snuck up on me, but I managed to draw my little goblins to celebrate the week! I love my children - they're like awful Pikmin. I've uploaded the whole parade as a print, as well as individual prints for each goblin. There's something very fu…

How to trust gpg keys via Travis Shears Personal Site October 27, 2023

After moving some GPG keys to a new computer I kept getting these trust warnings. It is NOT certain that the key belongs to the person named in the user ID.If you * really * know what you are doing, you may answer the next question with yes. Use this key a…

Generated by openring from webring