Gray Code, named after Frank Gray of Bell Labs, is a series of bytes or words where each byte/word in the series differs from the preceding BY ONLY ONE BIT. Example: 0, 1, 3, 2, 6, 7. These patterns have been used for testing logic circuits, communication transmissions, machine learning in AI, etc.
Generate a Gray Code pattern for values from 0 to 255:
FOR i = 0 TO 255
gray = i XOR (i \ 2) 'or (INT(i / 2))
' ...Here you print or output successive Gray Code values in GRAY.
NEXT i
Credit: Moneo, Agamemnus