Help required regarding binary format of R16 files

I am referring to the information found here : link text under “Calculating Height Map Z Scale”.

I am working with Python to convert some geotiff files to unreal raw files but I am striking a few problems with the description of the data not giving me the related bit locations as to where pieces of the number should be stored or as to how they are packed.

The Landscape technical guide initially says : “Unreal uses values between-256 to 255.992 and stored with 16 bit precision”. It then goes on to say “So to calculate a custom height requires the use of a ratio to convert your custom height value into the -256 to 256 range used by Unreal. Since the height range is a total of 512 units (-256 to 0 is 256 units and 0 to 256 is 256 units), the ratio is 1/512 or 0.001953125. We apply this by first converting our measurement to centimeters and then multiplying by the ratio”

Now I can figure out what they are trying to say here but what I can’t figure out is how said 16 bit binary number is formatted, I know that in order to get -256 I would need to use 9 bits I.E a sign bit of 1 to indicate negative followed by 8 zeros binary 100000000, being that we are talking at this point about a 16 bit quantity it logically remains that there must be another 7 bits to store the mantissa.

Have I got this completely wrong? I can not find anywhere how the information is stored, can someone please help me sort this out, note - an external program that does the conversion is absolutely useless to me I need to know how to do this myself due to the type and complexity of the data I am working with.

Thanks in advance.

r16 files are just unsigned short integers.

In Unreal, you can load file straight as is into TArray.

The height values will be from 0 to 65535.

Everything, that is below 32768 will be negative, above-positive.