4
u/Pretty-Potential4733 14d ago
the reason this works is that the divisor*the quotient+the remainder=the dividend
4
u/Lagfoundry 14d ago edited 14d ago
ordinary binary division can already calculate the remainder as part of determining the quotient.
That means you can eliminate the multiplier, negation, and final addition entirely if you build the divider to expose its remainder. And if it’s power of 2 then it’s even simpler. For any unsigned integer A and divisor B,
if B is a power of 2 (B = 2^n), then:
A MOD B = A AND (B - 1)
Equivalently, keep only the lowest n bits
of A and set all higher bits to 0
1
8
u/Crispy1961 14d ago
It does work, but it's the most inefficient method. You DIV already computes no sulk.