The difference between the binary representations of fractional and integer numbers is where that implicit binary point lies. The easiest way to explain this is with the attached diagram, which will be clearer and more concise than the thousand words it would take to explain things. What this means is that you can convert between the two formats by multiplying or dividing by 32767.0 for 16-bit numbers. For conversion to fractional values, the following macro was originally used:
#define CFF(x) (x * 32767.0)
There was a one-bit error in that computation, so now the Frac16 conversion macro is:
#define FRAC16(x) (x < 1 ? ( x >= -1 ? x * 0x7FFF : 0x8000) : 0x7FFF)
To convert back to ints, you'd use a divide operation. Double-check the header files and see if this conversion macro is already done for you.
One final note: be very careful and ensure that you're not mixing fractional variables with integer variables in a computation. You'll definitely get garbage out.
---Tom
Message Edited by J2MEJediMaster on 05-04-2006 03:06 PM
Message Edited by J2MEJediMaster on 05-04-2006 03:16 PM