07-02-2003, 08:20 PM
I did not code and test your pseudo code for Gray Code, it looked too complicated. However, I found the following simple algorithm among my stuff.Given the one line algorithm above, why would you want to do this recursively? Check it out, it works. You can generate bit patters wider than a byte, but the upper liimt of the FOR statement must end on a power of 2 (minus 1).
It's amazing how some programmers can complicate simple matters.
*****
Code:
REM Generate Gray Code bytes; i.e. values in range from 0 to 255.
DEFINT A-Z
FOR X=0 TO 255
GRAY = X XOR (INT(X/2))
rem Print or output the Gray Code value in GRAY.
NEXT X
It's amazing how some programmers can complicate simple matters.
*****