Converting fixed point to floating point

Started by
3 comments, last by Jesper T 19 years, 11 months ago
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.
Advertisement
Why are you using fixed point? Are you programming an 80386?
Hehe no, I''m trying to read level files for an old game.
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Ah, yes, that makes sense, thanks.

This topic is closed to new replies.

Advertisement