IntToGray is a bit operation conversion code snippet to convert an integer to Gray code. To convert a Gray code to an integer value, use GrayToInt.
//From http://www.richelbilderbeek.nl/CppIntToGray.htm int IntToGray(const int i) { return (i ^ (i>>1)); }