Python heightmap byte format binary

Hi,
I understand how heightmaps work but the problem I am having is that I am working in Python to convert my heightmaps from geotiff format to .r16 format and I don’t understand the binary layout of the 16 bit value that needs to be stored for unreal’s heightmap importer and how to achieve that as python does not support binary conversion of floats directly.

Unreal can have values between -256 to 255.992 according to Heightmaps under the section “Calculating Heightmap Z Scale”

The problem that I have is I don’t have any idea about how these are laid out in binary nor how to convert them as Python does not convert floats to binary directly and I don’t know how the resultant 16 bit value is packed - can someone please help me out.

Thank you in advance.

using the module struct you can work with binary data in python

>>> import struct
>>> f = 255.992
>>> b = struct.pack('f', f)
>>> b
b'\xf4\xfd\x7fC'
>>> struct.unpack('f', b)
(255.99200439453125,)