Division (digital) - Integer Division (unsigned) With Remainder

Integer Division (unsigned) With Remainder

The following algorithm, the binary version of the famous long division, will divide N by D, placing the quotient in Q and the remainder in R. All values are treated as unsigned integers.]]

if D == 0 then throw DivisionByZeroException end Q := 0 initialize quotient and remainder to zero R := 0 for i = n-1...0 do where n is number of bits R := R << 1 left-shift R by 1 bit R(0) := N(i) set the least-significant bit of R equal to bit i of the numerator if R >= D then R = R - D Q(i) := 1 end end

Read more about this topic:  Division (digital)

Famous quotes containing the words division and/or remainder:

    Slow, slow, fresh fount, keep time with my salt tears;
    Yet slower yet, oh faintly gentle springs:
    List to the heavy part the music bears,
    “Woe weeps out her division when she sings.”
    Droop herbs and flowers;
    Fall grief in showers;
    “Our beauties are not ours”:
    Oh, I could still,
    Like melting snow upon some craggy hill,
    Drop, drop, drop, drop,
    Since nature’s pride is, now, a withered daffodil.
    Ben Jonson (1572–1637)

    Do not undervalue the headache. While it is at its sharpest it seems a bad investment; but when relief begins, the unexpired remainder is worth $4 a minute.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)