I was talking to some students about how a number that’s stored in a word of computer memory is made up of individual bits, where each bit is either on or off (ie: one or zero).

To make this easier to understand, I created a little Java applet, which you can play with by clicking on the image below:

But then as I started to play around with this applet, I found myself creating an image of a musical keyboard.

That suggests an intriguing way to link numbers to music. If we assign one bit of any number to each note on the piano — as suggested in the image above — then any number becomes a musical chord.

Perhaps certain mathematical progressions will produce better music than others.

Hmmm.

The only problem with this mapping is that the chords will very rarely sound pleasing to the ear. The best chords are fractions; 1/2, 1/3, 1/5 etc. Pitches are already logarithmically distributed, so in using a logarithmic distribution (the bits of the bitstring) to determine which notes are played, the pitch is undergoing one more log.

11 and 100 will sound quite different, despite being only 1 apart in value.

So the question is what the bitstring contains; a number (in which case conside mapping a value to a note, so that 100 to 1000 is an octave rather than a tone) or a bitpattern like a mask (in which case carry on, as each bit signals a single thing, and patterns like 1000100010001000 have meaning). If the latter, I’d consider matching an octave to a characteristic chunk of the bitstring, for example 4 bits. That way you can assign Cs to the first of each quartet in ascending octaves, and complimentary notes like E(b) G Bb, or Eb Gb A, to the other bits.

The point is to look at what patterns of bits are meaningful to you, and to assign notes so that you can both discern them from others and glean useful information from listening to the instrumentation.

for (int i = 0 ; i <= 12 ; i++) play(17 << 12 – i);