user466534
user466534

Reputation:

Floating point in hexadecimal form

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

60123,124;

Upvotes: 3

Views: 1294

Answers (3)

Doug Currie
Doug Currie

Reputation: 41220

See this related question.

The %a printf format specifier is described here

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799240

<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'

Upvotes: 1

sje397
sje397

Reputation: 41862

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.

Upvotes: 1

Related Questions