Created
January 31, 2014 05:29
-
-
Save tshm/8727008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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