I'm interested in fixed-point arithmetic especially division operation. However many sites explain the way to do it only using power-of-two division, namely a bit shift.
What if the denominator is not power-of-two? How can we compute 1/3 in for example unsigned 16-bit arithmetic? Assuming the 4-right bits are fractional part.
1 is 0000 0000 0001 0000
3 is 0000 0000 0011 0000
If the denominator is not a power of two then the result is most likely to be an infinite series. For example:
Since you only have 4 fractional bits, the result will be:
You can calculate this by the following:
1000 0000 0000 0000
For the example above:
[1000 0000 0000 0000] / 3 = 0010 1010 1010 1010
[0010 1010 1010 1010] >> (12 - 1) = 0000 0000 0000 0101