I want to write a program that you give an input (number of digits n) and you get as an output a vector of all possible binary grey code generated.
For example,
if n=2, results should be:
V= {00, 01, 10,11}
Actually I am interested in having them bit by bit and not whole integer. Meaning I want to have a 2 D array of integers where I have each word in rows and bits (as int) in cols
Hint: Gray code of
numis(num>>1) ^ num. Go through all numbers of the0..2^N-1range, and compute their Gray code representation using this simple formula.EDIT Another hint: the simplest way to convert an integer to binary is using
bitset: