Dividing n-bit binary integers
Posted
by
Julian
on Stack Overflow
See other posts from Stack Overflow
or by Julian
Published on 2012-09-19T02:43:33Z
Indexed on
2012/09/19
3:38 UTC
Read the original article
Hit count: 140
c++
|pseudocode
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?
© Stack Overflow or respective owner