Latest recipes tagged "gray_code"http://code.activestate.com/recipes/tags/gray_code/new/2009-01-01T09:25:13-08:00ActiveState Code RecipesGray Code Generator/Iterator (Python)
2009-01-01T09:25:13-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/576592-gray-code-generatoriterator/
<p style="color: grey">
Python
recipe 576592
by <a href="/recipes/users/4168519/">Shao-chuan Wang</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/gray_code/">gray_code</a>).
Revision 3.
</p>
<p>Please refer to: <a href="http://en.wikipedia.org/wiki/Gray_code" rel="nofollow">http://en.wikipedia.org/wiki/Gray_code</a></p>
<p>The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only one digit.</p>
<p>The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems.</p>
<p>Example Gray Codes:
2-bit Gray code
00
01
11
10</p>
<p>3-bit Gray code
000
001
011
010
110
111
101
100</p>
<p>4-bit Gray code
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000</p>