In [1]:
import struct
import sys

In [2]:
f_max = sys.float_info.max

In [3]:
print(f_max)


1.7976931348623157e+308

In [4]:
print(struct.pack('>d', f_max))


b'\x7f\xef\xff\xff\xff\xff\xff\xff'

In [5]:
print(type(struct.pack('>d', f_max)))


<class 'bytes'>

In [6]:
print(struct.pack('<d', f_max))


b'\xff\xff\xff\xff\xff\xff\xef\x7f'

In [7]:
print(struct.unpack('>Q', struct.pack('>d', f_max)))


(9218868437227405311,)

In [8]:
print(type(struct.unpack('>Q', struct.pack('>d', f_max))))


<class 'tuple'>

In [9]:
print(struct.unpack('>Q', struct.pack('>d', f_max))[0])


9218868437227405311

In [10]:
print(type(struct.unpack('>Q', struct.pack('>d', f_max))[0]))


<class 'int'>

In [11]:
print(struct.unpack('>d', struct.pack('>d', f_max))[0])


1.7976931348623157e+308

In [12]:
print(hex(struct.unpack('>Q', struct.pack('>d', f_max))[0]))


0x7fefffffffffffff

In [13]:
print(type(hex(struct.unpack('>Q', struct.pack('>d', f_max))[0])))


<class 'str'>

In [14]:
def double_to_hex(f):
    return hex(struct.unpack('>Q', struct.pack('>d', f))[0])

In [15]:
print(double_to_hex(f_max))


0x7fefffffffffffff

In [16]:
print(double_to_hex(42.195))


0x404518f5c28f5c29

In [17]:
print(double_to_hex(1e500))


0x7ff0000000000000

In [18]:
print(double_to_hex(1e-500))


0x0

In [19]:
print(int(double_to_hex(f_max), 16))


9218868437227405311

In [20]:
print(bin(int(double_to_hex(f_max), 16)))


0b111111111101111111111111111111111111111111111111111111111111111

In [21]:
print(oct(int(double_to_hex(f_max), 16)))


0o777577777777777777777

In [22]:
def double_to_bin(f):
    return bin(struct.unpack('>Q', struct.pack('>d', f))[0])

In [23]:
def double_to_oct(f):
    return oct(struct.unpack('>Q', struct.pack('>d', f))[0])

In [24]:
print(double_to_bin(f_max))


0b111111111101111111111111111111111111111111111111111111111111111

In [25]:
print(double_to_oct(f_max))


0o777577777777777777777

In [26]:
def float_to_hex(f):
    return hex(struct.unpack('>I', struct.pack('>f', f))[0])

In [27]:
print(float_to_hex(42.195))


0x4228c7ae