I am trying to understand the working of gray code. If we give any non-negative integer n (where n is the number of bits) then we need to print its gray code sequence. Below are some examples
2-bit Grey Code sequence
Input = 2 bits
00 - 0
01 - 1
11 - 3
10 - 2
Output = [0,1,3,2]
3-bit Gray Code sequence
Input = 3
000 0
001 1
011 3
010 2
110 6
111 7
101 5
100 4
Output = [0, 1, 3, 2, 6, 7, 5, 4]
According to my understanding, gray code sequence begin with 0 and in a gray code two successive values differ in only one bit. I am not sure how the gray code of 2 came [0,1,3,2]
and how did the gray code of 3 came [0,1,3,2,6,7,5,4]