Dividing n-bit binary integers
- by Julian
Was wondering if anyone could help me with creating a pseudocode for how to go about dividing n-bit binary integers. Here is what I'm thinking could possibly work right now, could someone correct this if I'm wrong:
divide (x,y)
if x=0: return (0,0) //(quotient, remainder)
(q,r) = divide(floor(x/2), y)
q=2q, r=2r
if x is odd: r = r+1
if r >= y: r = r-y, q = q+1
return (q,r)
Would you guys say that this general pseudocode algorithm would accomplish the intended task of dividing n-bit numbers or am I missing something in my psuedocode before I start coding up something that's wrong?