Gray code n-th value

Write codeEasy10 minIntel and Nvidia style

Your task

Return the n-th value (0-indexed) of the standard reflected binary Gray code sequence, for non-negative n. Consecutive Gray code values differ in exactly one bit, which makes them useful for error-resistant encoders and in some communication/position-sensing systems. The closed form is simply n XOR (n >> 1). Return that value.

Examples

gray_code(n: int) -> int
Example 1
Inputgray_code(3)
Output2