tags:

views:

47

answers:

3

How can I represent a given floating point number in hexadecimal form? For example,

60123,124;
+1  A: 

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.

sje397
+1  A: 

<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'
Ignacio Vazquez-Abrams
A: 

See this related question.

The %a printf format specifier is described here

Doug Currie