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:

    Major [William] McKinley visited me. He is on a stumping tour.... I criticized the bloody-shirt course of the canvass. It seems to me to be bad “politics,” and of no use.... It is a stale issue. An increasing number of people are interested in good relations with the South.... Two ways are open to succeed in the South: 1. A division of the white voters. 2. Education of the ignorant. Bloody-shirt utterances prevent division.
    Rutherford Birchard Hayes (1822–1893)

    There are only three kinds of people: those who serve God, having found him; others who are occupied in seeking him, not having found him; while the remainder live without seeking him and without having found him. The first are reasonable and happy; the last are foolish and unhappy; those between are unhappy and unreasonable.
    Blaise Pascal (1623–1662)