Converting between IEEE 754 and Float (Format related

The float can be converted to well known single-precision IEEE 754 number, why 754? It's the standard representation of single-precision numbers, used in net transmission.

Compares to send the float as text or send/receive without re-formatting/un-formatting, it's much faster & safer. 

What confuses me is that nowadays floats are stored just what IEEE 754 says to be. Or maybe windows only?

But the most important thing is, when sending/receiving data/numbers, use standards.

See this page for more info.

I'll explain this format a little. It uses the first bit as a sign representation(1 if negative), the following 8bit as its exponential part, the last 23bit as its fraction part.

See this example:

1 10000001 10110011001100110011010

sign   expo       mantissa

It is divided as stated above.

The Microsoft's floats is following this standard. See the following definition of float in Windows. 

Where float uses 8 bits of exponent and 23 bits of mantissa, compares to double's 11 bits of exponent and 52 bits of mantissa.

About the bias refered to in the page above:

QUOTE

Because exponents are stored in an unsigned form, the exponent is biased by half its possible value.For type float, the bias is 127; for type double, it is 1023.You can compute the actual exponent value by subtracting the bias value from the exponent value.

/QUOTE

Note that this exponent's base is not 10, of course it's 2! So 2E127 is approximately 10E38, that's why float's range is about 1E-38~3E38!

转载于:https://www.cnblogs.com/sansna/p/5421648.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值