Gray Code
Submissions: 1960   Accuracy:

54.75%

  Difficulty: Basic   Marks: 1
Associated Course(s):   Sudo Placement 2019

You are given a decimal number n. You need to find the gray code of the number n and convert it into decimal.
To see how it's done, refer here.

Input:
The first line contains an integer T, the number of test cases. For each test case, there is an integer denoting the number

Output:
For each test case, the output is gray code equivalent of n.

Constraints:
1 <= T <= 100
0 <= n <= 108

Example:
Input

2
7
10
Output
4
15

Explanation:
Testcase1:
7 is represented as 111 in binary form. The gray code of 111 is 100, in the binary form whose decimal equivalent is 4.

Testcase2: 10 is represented as 1010 in binary form. The gray code of 1010 is 1111, in the binary form whose decimal equivalent is 15.
 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vanshika
Author: Vanshika_pec


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.