John Lam 1997 — 2026

Charles Petzold and Code

I love going to the Microsoft company store. After the end of my class this week, I went (for the second time) to the company store to pick up a few additional items. One item that caught my eye is a book that I’ve been putting off reading for quite some time (it was originally published in 1999). That book is called Code.

I’m writing this on a plane to Vancouver, BC. I just finished reading the first 40 pages of Charles’ book. I am so impressed by this book. It explains the origin of computer code from first principles. The beginning of the book is motivated by the desire of two best friends to communicate with each other after their parents have told them to go to bed. Based on this simple premise, he goes on to explain the origin of binary communications beginning with Morse Code.

The chapter on Morse Code brought back memories of something that I learned long ago in an Encyclopedia Brown book. That something was the frequency table of the English language, which is often used to crack simple substitution ciphers such as Ceasar’s cipher. Morse Code more-or-less follows the frequency table. The most commonly used letters are encoded using the fewest number of bits (E and T). The next most commonly used letters are encoded using two bits, (I, A, N, and M). This process is repeated for the remainder of the letters of the alphabet. While this sequence is somewhat different from the frequency table that I remembered from childhood, it was close enough.

The chapter on Braille was even more familiar to me. Braille is based on a 6-bit encoding scheme, which allows a maximum of 64 possible codes. Since only 26 of this codes are required for encoding the letters of the alphabet, the remainder of the codes are used to encode common words (and, but, the) and common two-letter combinations (ch, th, ed). This was so familiar because I had independently invented a similar scheme almost 20 years ago.

During high school, my part-time job was writing software for various companies. In those days, I wrote all of my software using 6502 assembly language for the Commodore series of computers (I owned or had in my possession a PET 2001, 4032. 8032, Super PET, Vic-20, Commodore 64, and Commodore 128 at various points in time). One application that I wrote was a replacement for the spell checker of a popular word processor called WordPro 64.

The original spell checker for WordPro 64 was written by Jim Butterfield, one of the original gurus of the Commodore world. While Jim was certainly an inspiration to all of us in those days, Jim’s code in this case, uh, sucked. It was unbelievably slow (I can’t remember exactly how long it took to spell check a document, but the times were somewhere in the neighborhood of ten minutes). Also, one of the ways that spell checkers competed with each other in those days was based on the number of words in the dictionary; Jim’s dictionary was pitifully small.

So what I needed to do was invent an encoding scheme that would allow me to pack more words onto a floppy disk. In those days the 1541 disk drive was the only disk drive available for the Commodore 64, and it stored a whopping 170K of data.[1] As it turns out, my encoding scheme was also 6 bits per character. I used the remaning 38 slots to encode a number of two letter abbreviations, and all of the common prefixes and suffixes for words. Using this scheme, I was able to average somewhere in the neighborhood of 2.5 bytes per word, which let us ship a 60,000+ word dictionary with the product. I am astonished by how similar my scheme was to the Grade 2 Braille scheme that Charles describes in his book.

I can’t wait to get back to reading Charles’ book. I was fortunate enough to meet Charles at various speaker events throughout the WinSummit conference last year. I can’t wait until we cross paths again so that I can tell Charles in person just how much I enjoyed his book. Great job!

[1] I find it amusing that my HP Jornada 568 comes with 64MB of RAM, and that I just added a 256MB compact flash card to it.

1 archived reader comment

**** (2004-12-02)

You are invited to visit the sites in the field of- Tons of interesdting stuff!!!