nineTENdo wrote:
Is there a book you can recommend on fixed-point math or more info on it?
Fixed point is quite simple. This name comes from the fact that there is a point, separating the integer part and the fractional part of a number (for example, 67.25). Since the point is fixed, the same number of bits is always used to represent each part.
If you want the numbers to fit in 8 bits, you have to sacrifice some of it's range for use in the fractional part. You could use a 4.4 format. 4 bits for each part. This would allow you to count from 0.0 to 15.9375, in 0.0625 increments.
You know how the value of the first bit is 1? And the value of the second bit is 2, the value of the third is 4, etc? That's 2^0 = 1, 2^1 = 2, 2^2 = 4, 2^3 = 8, etc. The same is true when you go backwards (towards the fractional part): 2^-1 = 0.5, 2^-2 = 0.25, 2^-3 = 0.125, 2^-4 = 0.0625. You don't
really need to know that, but it is better if you do.
Now, multiplication and addition with such numbers work normally. If you do 5.5 + 2.5 (01011000 + 00101000) = 8 (10000000), in our 4.4 format. To round it you simply dischard the bottom 4 bits (fractional part), resulting in a normal binary 8 (1000).
Multiplication and division will not work directly. Multiplying 2 4.4 numbers will give you a 8.8 result, so you have to divide that by 16 to get rid of the extra fractional part and go back to the format with only 4 bits in the fractional part. Division is the opposite, you'll get a number smaller than you wanted. So you should pad the dividend with 4 extra bits before dividing, to get a correct result within the format you're working with.
If it sounds complicated (I suck at explaining), look for some fixed point tutorials on the web, I'm sure there are plenty of them. Unfotunately I have none to recomend.