2012년 6월 13일 수요일

Integer division (unsigned)


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 no 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  

댓글 없음:

댓글 쓰기