Monthly Archives: April 2009

encoding – ha!

Given the last post, this is timely:


I have not written anything in a while.  Too busy I suppose.

In those two sentences are encoded all sorts of information.  We as humans understand each other through words, through sounds, through our own experiences, shared or otherwise.  So much information is encoded in our various forms of communication — it’s actually an incredible form of compression (probably lossy!)  A picture is worth a thousand words, but words can represent pictures, smells, feelings, etc. too.

As a programmer, I deal with encoding all the time.  Some forms are implicit — such as a UI element that initiates an action.  The user knows  (if I’ve done my job well) that clicking a button called “Start” will do something in the context of the application.  Other forms are more explicit — such as using bit fields in a struct to encode info about a network request.  But there are layers and layers of encoding going on — it’s one of the fundamental features of how computers work, and indeed how we work as humans.

This came up yesterday as my son (he’s 6) and I were taking apart an old mouse.  He’s been watching Make TV video podcasts lately, as he’s fascinated by how things work.  In one recent video, someone takes apart a mouse to get at the “rotary encoder” in the scroll wheel mechanism.  We found an old IBM mouse from @1990 that has the roller ball inside (as opposed to the newer laser mice).  The way these worked was pretty cool — there’s an LED facing a photosensor with a small wheel in between the two. The wheel contains a series of small slits around the circumference, and this is turned when the ball rolls.  This lets the light go through at intervals as the ball rolls.  There are two of these, one for the Y axis, one for the Y.  Here, let me encode this in a link, which should take you to a picture of what I’m babbling about:

So we were trying to figure this out and if we could use it for something else, and I used the word “decode”, which prompted him to ask “what is a decoder?”.    So we talked about morse code, and how letters encode sounds, and morse code encodes letters, and so on. Something like this:

Say I wanted to send a secret message to someone, and only we knew Morse Code (ha!).  I might wish to say:


Which translated into Morse Code would be:

. . . .   .   . _ . .   . _ . .   _ _ _

These dots and dashes are then encoded in sounds — short blips for dots, longer beeps for dashes. Specific amounts of space/silence to indicate letter and word boundaries.

The receiver of this encoded message would want to decode it, resulting in the message “Hello”. He’d know the code which would obviously enable him to do so.

However, what if “Hello” was code for “Begin the revolution”?  More encoding.  And on and on it goes.

This probably gets a little tedious, but it did get me thinking about machines and the human system.  Take for example music.  As a musician, I suppose I’m able to encode feelings and ideas into a musical form (if I’m doing it well, that is).  Some ideas are probably easier to encode — such as anger or sillyness.  Others are more complicated.

So back to work… I’ve been working on a framework for easily transmitting data (generally images, video or sound files) and metadata about those media.  Something that hides all the tricky stuff.  The previously mentioned bitfields are part of a message header that users of this framework can use to specify what kind of message is being sent, request, reply, error, etc.  Encoding this in a bit field makes it small, so the header can be transmitted quickly over potentially slow wireless networks.  Basic stuff really.  Another part of this is authentication and security.  Security and encryption gets at the very soul of encoding (or at least it’s evil conscience!) — it gets quite complicated.  A message contains a header and optionally a payload (e.g. it’s data).  That payload may have metadata as well as some media, which in turn may be compressed or not, and so on.  Then there’s the structure of the framework itself — there are classes for a ‘server object’ and a ‘client object’, a ‘message’ and a ‘message hub’.  Part of the point of object-oriented programming is to encapsulate functionality into an object so that as humans we can deal with the inherent complexity in easier to grok pieces (objects).  Without all this encoding, it would be a big mess.

Conclusion?  Errr… uh… I guess we’re complicated entities in a complicated system and capable of great beauty or great ugliness, or infinite variations thereof?

I guess that’s enough for now.