# Those Who Remember Gray Code

Most people in the electronics world are familiar with the now quite old and trite pun: "There are 10 types of people in the world. Those who understand binary and those who don't."

If you never had the privilege of learning to count or add in binary, the pun is considered funny because 10 in binary is equal to 2 in our normal decimal system. So, people who don't know binary think you're saying there are ten types of people, but you're really saying there are two type of people. Get it? It's funny. Really it is. Ha. Ha. Ha.

Or, at least it was funny the first million times someone said it.

It has always kind of bothered me though. In decimal (base-10), we tend to start counting from 1. Zero certainly does exist in the decimal number system, but it hasn't always been in our counting lexicon. Convention is to not include it as an option when counting things, because when we are babies, we hold up one finger and then two and so on. one, two, three, four... You start with one cookie and go from there.

In the digital world, however, we tend to start counting at zero. Most programming language compilers start array indexes with zero. With hardware, the off state for a register or memory cell is zero. If we only have one bit, we have two states: zero and one. It's like a light switch. There is on and there is off: two states. Given that, if us electronicy people are trying so hard to show how "clever" we are, why would the joke not be: "There are 1 types of people in the world. Those who understand binary and those who don't." In binary, the first two counts are 0 and 1. That is equivalent of decimal 1 and 2.

Seeming random segue alert:

In early June, 2019, I needed to design a t-shirt for me to wear at the Teardown Portland conference. I have a lot of shirt ideas, but for some reason, this particular pun was on my mind. I thought it might be kind of fun to use the "10 types of people" trite phrase, but freshen it up by changing it to accommodate the fact that 10 binary really encompass three states, not two. That would give me: "10 types or people, those who understand binary, those who don't, and programmers that start with 0."

Then, digging back into the deepest reaches of obscure memory, because that is what I do, I remembered Gray code. Gray code is an early derivative of binary that was designed to better accommodate mechanical switches. In Gray code, each successive number only requires one bit to change value.

Counting in binary, we see this:

Decimal | Binary | |

0 | 000 | |

1 | 001 | Only the first bit changes value |

2 | 010 | Two bits, the first and second, change value |

3 | 011 | One bit, the first bit, changes value |

In Gray code, no matter how high the count there is never more than one bit changing value at one time. We see this:

Decimal | Gray | |

0 | 000 | |

1 | 001 | One bit changes value |

2 | 011 | One bit changes value |

3 | 010 | One bit changes value |

So, in common binary, 10 equals decimal 2, but from the perspective of a programmer or digital logic person starting at 0, covers three values. In Gray code, 10 equals decimal 3 and covers four values if you start from zero. My Gray code, and final shirt version, has: "10 types or people: those who understand binary, those who don't, those who remember Gray code, and programmers that start with 0."

That's probably way more detail related to the origin of a t-shirt than anyone really needs, but there you have it. Just don't get me started on what the actual order of the types should be...

Duane Benson

Decimal is called "base-10" because there are ten steps before it rolls over to using two digits

Binary is called "base-2" because there are two steps before the rollover.

But 10 binary equals 2 in decimal, so shouldn't binary also be called "base-10"?

@Mark. Ummmm. Yep. I did do that... It is correct here in the blog, (where I could have easily changed it) but it is incorrect in the print version.

Posted by: Duane Benson | October 17, 2019 at 10:59 AM

I just received a hard copy of Circuit Talk Vol 3 Issue 2. To the editor: Did you really cut/paste the incorrect Gray code sequence on Page 6? LOL. I guess we're only humans after all. -Mark.

Posted by: Mark Belcher | October 09, 2019 at 07:45 AM

I remember learning about Gray code in college, but I don't think I saw it after that.

I liked the part about how there were four items in the set because programmers start with zero.

Posted by: Charles J Gervasi | July 23, 2019 at 12:46 PM