Skip to content

Latest commit

 

History

History
40 lines (23 loc) · 1.36 KB

CppGrayToInt.md

File metadata and controls

40 lines (23 loc) · 1.36 KB

 

 

 

 

 

 

GrayToInt is a bit operation conversion code snippet to convert the integer value from a Gray code. To convert a Gray code to an integer, use IntToGray.

 


//From http://www.richelbilderbeek.nl/CppGrayToInt.htm //Modified from Press et al., 2002, Numerical Recipies in C++, //ISBN 0 521 75033 4 int GrayToInt(int i) {   int power = 1;   while (1)   {     const int j = i >> power;     i ^= j;     if (j == 0 || power == 16) return i;     power <<= 1;   } }