Skip to content

Instantly share code, notes, and snippets.

@tshm
Created January 31, 2014 05:29
Show Gist options
  • Save tshm/8727008 to your computer and use it in GitHub Desktop.
Save tshm/8727008 to your computer and use it in GitHub Desktop.
int graycode(int in) {
int out = in & 0xFFFF;
for (int i=0; i<16; i++) {
// if certain bit is 1 then rest of bits get flipped else no change.
if (out & (0x8000 >> i)) {
out ^= (0xFFFF >> (i+1));
}
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment