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:
“Imperialism is capitalism at that stage of development at which the dominance of monopolies and finance capitalism is established; in which the export of capital has acquired pronounced importance; in which the division of the world among the international trusts has begun, in which the division of all territories of the globe among the biggest capitalist powers has been completed.”
—Vladimir Ilyich Lenin (18701924)
“Then I had only prisoners thoughts. I awaited the daily walk which I took in the yard, or my lawyers visit. I managed the remainder of my time very well. I have often thought that if I was made to live in a dry tree trunk, without any other occupation but to watch the flower of the sky above my head, I would have gradually gotten used to it.”
—Albert Camus (19131960)