Skip to content

Instantly share code, notes, and snippets.

@catid
Created December 14, 2016 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catid/16972ad888bcf913321aaaf5acc00e19 to your computer and use it in GitHub Desktop.
Save catid/16972ad888bcf913321aaaf5acc00e19 to your computer and use it in GitHub Desktop.
// Get the next bit to flip to produce the 8-bit Gray code at the provided index
// Precondition: index > 0 and index < 256
static int GetBitFlipForGrayCode8(int index)
{
if (index & 1)
return 0;
if (index & 15)
return (0x6764 >> (index & 14)) & 3;
return ((0x12131210 >> (index >> 3)) & 3) + 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment