I was looking at the binary integer division with remainder section in Wikipedia and was wondering how would I translate this into another language like C for example?
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
I know how to translate the majority of it and do the bit shifting, but how would I do something like R(0) = N(i)
or Q(i) = 1
when they are integers and not a function or a function pointer? Sorry for the basic question, the little section just got me interested.