User:Albedo: Difference between revisions
Content added Content deleted
m (→Binary Digits) |
m (→Binary Digits) |
||
Line 274: | Line 274: | ||
2X/= : divide n by 2 and duplicate the result |
2X/= : divide n by 2 and duplicate the result |
||
1X!>#: is the result >0? (is n>=2?) It is, thus rotate the pointer by 1 (downwards, continue at l2) and go through the loop |
1X!>#: is the result >0? (is n>=2?) It is, thus rotate the pointer by 1 (downwards, continue at l2) and go through the loop |
||
l2: 2X1X@: move the result down (needed for further processing), and move n to the top of the stack |
|||
2X% : n mod 2 (remainder, last binary digit) |
2X% : n mod 2 (remainder, last binary digit) |
||
2X1X@: move binary digit down, move result of division up |
2X1X@: move binary digit down, move result of division up |
||
loop is finished, back to the beginning (l1) |
loop is finished, back to the beginning (l1) |
||
l1: = : duplicate result of division |
|||
2X/= : divide n by 2 and duplicate the result |
2X/= : divide n by 2 and duplicate the result |
||
1X!>#: is the result >0? (is n>=2?) It is not, thus don’t rotate the pointer and move on ( |
1X!>#: is the result >0? (is n>=2?) It is not, thus don’t rotate the pointer and move on (towards l3) |
||
? : pop division result from the stack |
? : pop division result from the stack |
||
l3: N : output first bit: 1 (1*2^1) |
l3: N : output first bit: 1 (1*2^1) |