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:

    O, if you raise this house against this house
    It will the woefullest division prove
    That ever fell upon this cursed earth.
    William Shakespeare (1564–1616)

    The route through childhood is shaped by many forces, and it differs for each of us. Our biological inheritance, the temperament with which we are born, the care we receive, our family relationships, the place where we grow up, the schools we attend, the culture in which we participate, and the historical period in which we live—all these affect the paths we take through childhood and condition the remainder of our lives.
    Robert H. Wozniak (20th century)