/* FloatToFixed converts a float in the range (0,1) to a fixed point 16 bit binary stored as an unsigned integer. It converts negative numbers to zero and numbers bigger than one to the largest fixed point representation available. MaxNum should be the largest power of 2 representable in our unsigned integers. */ unsigned int FloatToFixed(float x, unsigned int MaxNum) { unsigned int n; if(x<0) n=0; else if(x>1) n=MaxNum; else n = (x*MaxNum); return n; }