Recursive on Gray Code

256 Views Asked by At

I have been curious since working on gray code that how can I write recursive function to calculate the integer that appear in position m of n-bit (as show in the link that I provide) like 3-bit Gray Code at position 5 is 7.

https://commons.wikimedia.org/wiki/File:Binary-reflected_Gray_code_construction.svg

Figure: The Reflect and Prefix Method.

General Information

Gray Code is an ordering of the binary numeral system such that two successive values differ in only one bit (binary digit). For example, gray code of 3 digits (and its decimal) are listed as follows:

000 = 0, 001 = 1, 011 = 3, 010 = 2, and vice versa which is simple binary number.