Pythonで浮動小数点数をビットパターンに変換する方法

64bit浮動小数点数(1.0の例)

>>> import struct
>>> hex(struct.unpack('<Q', struct.pack('<d', 1.0))[0])
'0x3ff0000000000000'

32bit浮動小数点数(1.0の例)

>>> import struct
>>> hex(struct.unpack('<I', struct.pack('<f', 1.0))[0])
'0x3f800000'

16bit浮動小数点数(1.0の例) Python3.6以上で動く

>>> import struct
>>> hex(struct.unpack('<H', struct.pack('<e', 1.0))[0])
'0x3c00'