# How can I tell if a bit pattern can represent offset gray-code?

I have a very poor understanding of gray code in general and I find it to be a difficult thing to learn. While trying to learn about it I stumbled upon this seemingly looking trivial question that I can't answer.

Can the bit pattern 01110011 represent offset gray-code?

What is "gray-code" and how do I construct it and recognize offset gray-code?

Yes. Any bit pattern can represent an offset gray-code number. Gray code is an ordering of the binary numeral system such that two successive values differ in only one bit (binary digit).To fully understand it you need and example and compare with default binary. In binary:

1-> 0001
2-> 0010
3-> 0011


You can see that in binary when incrementing from 1 to 2, there are happening two bit operations. One is that the first bit turns off and second the 2'nd bit lights up. So this violates the rule of gray-code - "two successive values differ in only one bit".

In gray code it would look like this:

1-> 0001
2-> 0011
3-> 0010


Can you see the difference? When we incremented from 1 to 2, the first bit didn't turned off anymore and the second lighted up. So only one bit operation happened.

You can also check out this article which has a C program that generates gray-codes between 1-32 bits. Using-Gray-Codes