Converting integers to fixed point¶
Converting an integer to its fixed point representation is even easier. All you need to do is multiply the value by 256.
Or in simple terms, move all the bits to the left 8 places. Even an 8bit CPU can shift bits quickly.
#define FIXED_SIZE 8 #define FIXED_TO_INT(x) (x >> FIXED_SIZE) #define INT_TO_FIXED(x) (x << FIXED_SIZE)