Converting fixed point to floating point
Ok, I have a fixed point number where the low 16 bits is fractional, and the high 16 bits is the integer. I am not quite sure how it is encoded, but I assume there is a standard way.
Say the number is this one:
First 16 bit int: -1262
Last 16 bit int: 8973
Should this translate into
(float)(-1262) - (float)8973 / 10000.0f = -1262.8973
or do I have to consider the last 16 bits as a fraction of the maximum value that 16 bits can have, ie:
First 16 bit int: -1262 = 0x84ee
Last 16 bit int: 8973 = 0x230d
Translates into (float)(-1262) - (float)8973 / (float)0x0000ffff
And the fraction part is unsigned anyway right?
Thanks in advance.
I would think that it would be -1262.136917 or so. -1262 is the top 16 bits, and then the fractional portion would be divided by 2^16 (not 2^16 - 1, I believe). This way (in hex) .FFFF would equal 65535 / 65536, just as .9999 in decimal is 9999/10000.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement