Division Algorithm - 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 Algorithm

Famous quotes containing the words division and/or remainder:

    If the technology cannot shoulder the entire burden of strategic change, it nevertheless can set into motion a series of dynamics that present an important challenge to imperative control and the industrial division of labor. The more blurred the distinction between what workers know and what managers know, the more fragile and pointless any traditional relationships of domination and subordination between them will become.
    Shoshana Zuboff (b. 1951)

    Most personal correspondence of today consists of letters the first half of which are given over to an indexed statement of why the writer hasn’t written before, followed by one paragraph of small talk, with the remainder devoted to reasons why it is imperative that the letter be brought to a close.
    Robert Benchley (1889–1945)