[Math] binary division and remainder

binary

Q=A/B , Q is a real number expressed as a pair of 8 bits:

  • most significant 8 bits for the integer part
  • least significant 8 bits for the fractional part
  • the number is unsigned

for example:

0 0 1 0 1 1 0 1 . 0 1 0 1 0 0 0 0

Can you find the remainder of division if you know B?

example: 44/20

0010 1100 . 0000 0000 / 0001 0100 . 0000 0000

= 0000 0010 . 0011 0011 (2.1999…)

Now, to find the reminder I should multiply(0.19… * 20) 0000 0000 . 0011 0011 * 0001 0100 . 0000 0000

= 0000 0011 . 1111 1100

Now, can I say that the number is 4 because is greater than 3.5? I don't think this works for all the numers

There are exceptions, for example A=2 and B=172, I wonder if increasing the fractional part bits number solves the problem

2/172 :

0000 0010 . 0000 0000 /

1010 1100 . 0000 0000

=0000 0000 . 0001 0010

0000 0000 . 0001 0010 *

1010 1100 . 0000 0000

=0000 0000 . 1100 0001 (should be 2, or at least something greater than 1.5)

Best Answer

You should be multiplying the fractional part by the original denominator, not by the original numerator. Look at the same division in base ten: you get $2.2$, and the remainder is $0.2\cdot20=4$, which is correct.

After dividing $a$ by $b$, you have an integer part $n$, say, and a fractional part $\alpha$: $\frac{a}b=n+\alpha$. Multiplying both sides by $b$ gives you $a=nb+\alpha b$, or $\alpha b=a-nb$; clearly $\alpha b$ here is the remainder.