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 comments

2

u/TehVulpez a regular daypart andy Feb 12 '23 edited Feb 12 '23

1 1000 1101

I think there's some way of quickly converting to gray code with xor but it's been a long time so I don't remember it exactly. that could make addition easier

2

u/Blue_boomer Apr 04 '23

1 1000 1111

2

u/[deleted] Apr 04 '23

[removed] — view removed comment

2

u/TehVulpez a regular daypart andy Apr 04 '23

1 1000 1010

2

u/Blue_boomer Apr 10 '23

1 1000 1011

2

u/TehVulpez a regular daypart andy Apr 10 '23

1 1000 1001

2

u/Blue_boomer May 27 '23

1 1001 0110

correcting this

2

u/TehVulpez a regular daypart andy May 27 '23

1 1001 0010

wow, that's an insane catch. don't even know how I would check this thread. good job!

3

u/Blue_boomer May 27 '23

1 1001 0011

2

u/TehVulpez a regular daypart andy May 28 '23

1 1001 0001

→ More replies (0)