These characteristics suggest a simple and fast method of translating a binary value into the corresponding Gray code. Each bit is inverted if the next higher bit of the input value is set to one. This can be performed in parallel by a bit-shift and exclusive-or operation if they are available: g(b) = x(b) XOR x(b+1)

```
class Solution:
# @param {integer} n
# @return {integer[]}
def grayCode(self, n):
return [(i>>1)^i for i in xrange(2**n)]
```