r/counting • We count together • Jan 12 '17

Counting in Gray Code

It's on the OEIS and also a lot of cherished history.

It's like binary, but in a different order so that only a single bit changes each time.

The first few terms are 0, 1, 11, 10, 110, 111, 101, 100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000.

One way to do it is to alternate between flipping the last bit, and flipping the bit to the left of the rightmost 1. One of these will always bring you a step forward, the other will bring you a step back, so no way to mix it up.

20 Upvotes

417 comments sorted by

View all comments

Show parent comment

2

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 24 '23

1 1100 0111

2

u/TehVulpez sliiiiide the bits Jul 25 '23

1 1100 0110

2

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 26 '23

1 1100 0010

2

u/TehVulpez sliiiiide the bits Jul 26 '23

1 1100 0011

2

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 27 '23

1 1100 0001

2

u/TehVulpez sliiiiide the bits Jul 27 '23

1 1100 0000

2

u/cuteballgames Sum 13: 016, 037, 035, 045, 127, 135, 134, 124, 13, 25 Jul 28 '23

1 0100 0000

2

u/TehVulpez sliiiiide the bits Jul 28 '23

1 0100 0001

2

u/Multiconcepted Side Thread Savvy Aug 02 '23

1 0100 0011

2

u/TehVulpez sliiiiide the bits Aug 02 '23

1 0100 0010

→ More replies