Thursday, July 02, 2009

Alternative Hexadecimal Digits

I'm not complaining about the convention of using characters 0-9 and A-F as hexadecimal digits. It's a good system; it's easy to learn, since most of us in the Western World have known the meaning of 0-9 and the order of the alphabet since childhood. But what if we could start over with only practical concerns (apart from the value of keeping a well-recognized and heavily-used convention) to guide us?
I can think of a few desirable traits for a set of hexadecimal digits:
  1. They should be easy to learn.
  2. It should be easy to write them by hand quickly without them being ambiguous or difficult to read.
  3. They should be representable using the common LCD/LED displays used in clocks, calculators, etc.
  4. They should depict their binary counterparts somehow. In software, we must sometimes translate between hexadecimal and binary, e.g. to determine whether a given bit in a given word is 1 or 0. If the oneness or zero-ness of each bit in a nibble was visibly represented in its corresponding digit, this translation would be easier.
With these in mind, I came up with an alternative set of hexadecimal digits. Yes, I am a nerd.
In handwritten form:

For LCD/LED displays:





Description of This Alternative

First off, the digits for zero and one are the same as in conventional binary, octal, and decimal.

Next, a definition: the binary composition of a number is the set of integral powers of 2 that add up to that number. For example, the binary composition of 76 is the set {64, 8, 4} or {26, 23, 22}, since its members are integral powers of 2 and they add to 76.

With this definition in mind, the following are true of the alternative digit for a given number 1-15:
  • If one is part of a number's binary decomposition, its digit faces right otherwise it faces left. Equivalently, the digits for even numbers face the same direction as 'e' and 'n', and the digits for odd numbers face the same direction as 'd'.
  • The digit has a stroke across its base if and only if two is part of the number's binary composition.
  • The digit has a stroke across its middle if and only if four is part of the number's binary composition.
  • The digit has a stroke across its top if and only if eight is part of the number's binary composition.

Some Benefits of This Alternative

 Because of these rules, if a hexadecimal digit is depicting a nibble of memory (e.g. in a hex dump program), one only has to look at a certain part of the digit to see if a particular bit is set to 1 or 0. Also, those of you who know about electronic logic gates can tell that the circuitry needed to take a four-bit input representing a number and light up the proper parts of an LED/LCD digit display would be a bit simpler these digits than with the conventional digits.

Update: I've been collaborating with Valdis Vītoliņš on a new set of alternative hexadecimal digits.  They are an improvement on the digits described in this post.  See this blog post.