Ok, this is maiking my head hurt. To save on floating-point-maths libraries, i've written my own fixed-point maths routines.

Say I enter in 1.5 into my keypad. To convert this with my routine, first I store 1 into a unsigned long, then I shift it two bytes and OR it with the 5:

000000000000000000010000010100000000

I can then later extract the 1 by getting the upper int, adding a decimal point onto my LCD and then adding the lower int (with appropriate itoa conversion function, of course).

The problem comes later. Say I have another number, like 150. I shift this two bytes too:

000000000000100101100000000000000000

Ok, that's the easy bit. Now, I need to divide my first number by four and subtract it from the first number. How the hell do I do this? I've been pondering it all afternoon, and have tried all sorts of convulted routines which waste a lot of time and flash space. How do I turn my first unsigned long into the equivelent of 1.5 which I can shift right twice to divide it b four to get:

000000000000000000011000000000000000

All help appreciated. I think i'm gonna have to bite the bullet and just use floating point maths routines :(.

- Dean :twisted: