In the binary-reflected Gray code, consecutive values differ in exactly one bit. The value at index n (0-indexed) is given by n XOR (n >> 1).
Output the Gray code value at index n.
One line: a non-negative integer n.
One line: the nth Gray code value.
Example 1
Input
5
Expected
7
Explanation
5 XOR 2 = 7, so the 5th Gray code value is 7.
Example 2
Input
0
Expected
0
Explanation
0 XOR 0 = 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →