【发布时间】:2021-05-12 09:18:43
【问题描述】:
Wiki 表示以下算法是长除法的一个版本。有谁知道数学上发生了什么 R 被左移,然后 R(0) 的最低有效位被设置为 N(i)?
我知道左移是 2R,但在那之后我有点迷茫。
if D = 0 then error(DivisionByZeroException) end
Q := 0 -- Initialize quotient and remainder to zero
R := 0
for i := n − 1 .. 0 do -- Where n is number of bits in N
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
【问题讨论】:
标签: algorithm binary division integer-division