def gray2int(g, size):
 res = 0
 for i in reversed(list(range(size))):
  gi = ((g >> i) % 2)
  if (i == (size - 1)):
   bi = gi
  else:
   bi = (bi ^ gi)
  res += (bi * (2 ** i))
 return res

def gray2int ( g , size ) : res = 0 for i in reversed ( list ( range ( size ) ) ) : gi = ( ( g >> i ) % 2 ) if ( i == ( size - 1 ) ) : bi = gi else : bi = ( bi ^ gi ) res += ( bi * ( 2 ** i ) ) return res
transforms a gray code back into an integer .