开发者

Floating point in hexadecimal form

开发者 https://www.devze.com 2023-01-08 10:33 出处:网络
How can I represent a given floating point number in hexadec开发者_开发技巧imal form? For example,

How can I represent a given floating point number in hexadec开发者_开发技巧imal form? For example,

60123,124;


<sign>0x1.<mantissa>p±<exponent>

>>> (1.2).hex()
'0x1.3333333333333p+0'
>>> (1125.2).hex()
'0x1.194cccccccccdp+10'
>>> (7e85).hex()
'0x1.204362b6da56fp+285'
>>> (5e-3).hex()
'0x1.47ae147ae147bp-8'
>>> (-8.).hex()
'-0x1.0000000000000p+3'

>>> (60123.124).hex()
'0x1.d5b63f7ced917p+15'


Here (AU) we use a decimal point:

60123.124

Which my calculator converts to hex like so:

0xEADB.1FBE76C8B43958106

The principle is the same: where in base 10 the first decimal place represents 10ths, in base 16 the first decimal place represents 16ths.


See this related question.

The %a printf format specifier is described here

0

精彩评论

暂无评论...
验证码 换一张
取 消