Home -> Magazines -> Issues -> Articles in this issue -> View

## What The Heck's Hex? | |

*Proving that too much hex isn't bad for the health, Martin Russ explores the numeric world of 16.*

**Proving that too much hex isn't bad for the health, Martin Russ explores the numeric world of 16.**

When I was at school, Binary arithmetic was just becoming fashionable. Computers were taking over and the maths teacher kept telling us that soon everyone would need to know that 10110 plus 100101 came to 111011, and be able to multiply 101 by 11 to get 1111 in their head. It probably doesn't need me to inform you that things never quite happened that way. Instead, computers have become very adept at presenting numbers in good old familiar decimal (0-9). Binary, with its 1s and 0s mentality, seems to be restricted to electronics engineers and digital designers, not real life.

However, the rise of 16-bit computers and MIDI has meant that Hexadecimal, not Binary, has become the required second language of the musical elite. MIDI especially seems to revel in obscure symbols like $F7. So what does it all mean in musical terms?

Luckily for musicians, hexadecimal ('hex' for short) has quite a few parallels with the way music works, so rather than talk mathematics I intend to talk music. Let's start with 4/4 time.

When counting musical beats (eg. '1... 2... 3... 4... 1... 2...' etc), each time you count up to four you know that a new bar is about to start, and it starts with the first beat (crotchet) of that bar. In this numbering scheme for beats, there are only four possible symbols for the numbers: 1, 2, 3 or 4. You would never count the number 7 because there are never more than four beats in a bar of 4/4 music.

Suppose that instead of having four crotchets or quarter notes in a bar of 4/4, we had eight quavers or eighth notes. Counting these would give a different numbering scheme: '1.. 2.. 3.. 4.. 5.. 6.. 7.. 8.. 1.. 2.. 3.. 4..' etc. In this case we only ever count up to 8, because there can only ever be eight quavers in a bar of 4/4. There is no need for number symbols like 9 or 10.

If we now halve the time of these quavers to semiquavers (16th notes), then there will be 16 of them in a bar of 4/4. Counting them will result in the following: '1.. 2.. 3.. 4.. 5.. 6.. 7..8.. 9.. 10.. 11.. 12.. 13.. 14.. 15.. 16.. 1.. 2..' etc. As before, these 16 symbols are all we need to be able to count the number of semiquavers which can occur in a single bar of 4/4. There is a problem with the symbols, though - the last seven are all made up out of two other symbols, and so the symbols are not all unique. Also, imagine that there are no semiquavers in the bar at all - how would we show that?

To solve these two problems we need to alter the symbols slightly. Music already uses letters of the alphabet to represent notes, so let's do the same with the symbols we need. Therefore, A will replace 10, B will replace 11, and so on. The 16 semiquavers are now counted as follows: '1.. 2.. 3.. 4.. 5.. 6.. 7.. 8.. 9.. A.. B.. C.. D.. E.. F.. G.. 1.. 2.. 3..' etc. We now have a single unique symbol for each number of semiquavers. Borrowing the number 0 (zero) from ordinary arithmetic solves the second problem - that of representing an empty bar. The set of symbols we have just developed now looks like this:

**0 1 2 3 4 5 6 7 8 9 A B C D E F G**

If there are 16 semiquavers in a bar of 4/4, we could say that the bar is full. Instead of using the G symbol to show these 16 semiquavers, it might be easier to say '1 bar'. Taking a clue from conventional decimal numbers, we could use the position to show bars and semiquavers.

For example, the semiquaver arithmetic notation for 16 semiquavers would show 10, meaning one bar (of 16 semiquavers) and no others. 11 would therefore mean there was just one semiquaver in the second bar.

To avoid confusion, we need to show that this notation is not the same as ordinary decimal numbers: since we are counting semiquavers, the $ symbol is a good choice. So $10 is one full bar of semiquavers, and $11 is one full bar and one semiquaver.

Using this method to count notes in bars quantised to semiquavers gives us the following series of numbers: $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $A, $B, $C, $D, $E, $F, $10, $11, $12 etc. With the addition of the symbols A to F, the 0 and the $, we can now show and count semiquavers in a sensible way. If I asked you to tell me where the 28th semiquaver in a piece of 4/4 music was, could you tell me? If I then asked you where the $1Cth semiquaver was, you should be able to quickly tell me that it is in the second bar (the first bar is full - remember what the 1 means) and the $C is equivalent to the 12th semiquaver in that bar.

So which do you prefer? Try covering the answers on the right-hand side of the questions which follow:

Semiquaver | $ notation | Bars | Semiquavers into next bar |

10 | $A | 0 | 10 |

22 | $1C | 1 | 12 |

48 | $30 | 3 | 0 |

79 | $4F | 4 | 15 |

84 | $54 | 5 | 4 |

214 | $D6 | 13 | 6 |

As you can probably see, the $ notation makes the task dead easy - you don't need to divide by 16 and see what the remainder is, because that is how it is written out! This strange system is actually useful.

Decimal | Hex ($) |

10 | $A |

11 | $B |

12 | $C |

13 | $D |

14 | $E |

15 | $F |

16 | $10 |

20 | $14 |

30 | $1E |

40 | $28 |

50 | $32 |

60 | $3C |

70 | $46 |

80 | $50 |

90 | $5A |

100 | $64 |

110 | $6E |

120 | $78 |

127 | $7F |

130 | $82 |

140 | $8C |

150 | $96 |

160 | $A0 |

170 | $AA |

180 | $B4 |

190 | $BE |

200 | $C8 |

210 | $D2 |

220 | $DC |

230 | $E6 |

240 | $F0 |

250 | $FA |

255 | $FF |

It turns out that this counting up to 16 is also useful in computers - it is called *hexadecimal*, from 'hexa' meaning six and 'decima' meaning ten. Although computers really count only in ones and zeros (binary), they can be persuaded to count in other ways, and the easiest of these ways involves powers of 2 - there are two symbols: 0 and 1. The powers of 2 are: 2, 4, 8, 16, 32, 64, 128 etc. Of these, the number 16 looks familiar in the context of our $ notation, and in fact we can use our $ notation to converse with computers. Rather than count semiquavers, computers prefer binary digits (*bits* for short) - but the notation is exactly the same.

So, in computer terms, $2E means two complete sets of 16 bits (two full bars in music notation) and 14 extra bits (14 semiquavers). Why would we want to show computer information in this form?

Consider what 16 ones and zeros look like: 1011101011011011. Wouldn't *you* prefer to see this as a four-digit hex number ($6ADB)? I know which one I could remember easily. Computers normally deal with bits in groups of eight at a time - and these are called a *byte*.

Each byte can be represented by two hexadecimal symbols or digits - this is why the 16 binary digits in the last example produced a four-digit hex number.

The best news about hex is that you do not need to know any more than you do now. To be able to use a computer you do not need to know any hex arithmetic (the computer will do that!), so there will be no struggling with $EA x $3F for homework! Instead, you just need to know that moving to the left produces groups of 16, just as in ordinary decimal arithmetic you have units, tens (10), hundreds (10 x 10), thousands (10 x 10 x 10) etc. In hexadecimal, the equivalent groups are 16, 16 x 16 (256), 16 x 16 x 16 (4096) etc.

This should give you a clue about how to convert between decimal and hex. Faced with an unfamiliar hex number such as $D2, you just take the $D and multiply it by 16 (it represents complete sets of 16s) - $D=13, and 13x16 is 208 - and adding the $2 gives 210 in decimal. Converting the other way is just a matter of dividing by 16 and finding the remainder: for example, 182 divided by 16 gives 11.375. Ignoring the decimal places, we now know that the left-most hex digit is 11 ($B). And 11 x 16 is 176. Subtracting 176 from 182 leaves a remainder of 6. Therefore, the hex number for decimal 182 is $B6.

Because most computers work with either 8 or 16 bits as standard, you will usually only come across two-digit or four-digit hex numbers. The range of decimal numbers that you can cover with just four hex digits is quite large - from $0000 to $FFFF is the same as 0 to 65,535. For two digits the range goes from $00 (decimal 0) to $FF (decimal 255). I have included a quick reference table which should help you to convert between hex and decimal.

I hope this brief tutorial opens up the world of hexadecimal to you. If you were expecting something complex then the dividing and multiplying by 16 may have come as a shock - calculators can do it with ease, and even my mental arithmetic can cope with the first few entries in the 16-times table! More importantly, Hex is not a way of clouding the workings of computers, it is a way of making them easier to work with because it suits the method the computer uses to deal with numbers. And anyone working with MIDI System Exclusive data will experience hexadecimal numbers all the time.

1 x 16 = 16 = $ 10

2 x 16 = 32 = $ 20

3 x 16 = 48 = $ 30

4 x 16 = 64 = $ 40

5 x 16 = 80 = $ 50

6 x 16 = 96 = $ 60

7 x 16 = 112 = $ 70

8 x 16 = 128 = $ 80

9 x 16 = 144 = $ 90

10 x 16 = 160 = $ A0

11 x 16 = 176 = $ B0

12 x 16 = 192 = $ C0

13 x 16 = 208 = $ D0

14 x 16 = 224 = $ E0

15 x 16 = 240 = $ F0

16 x 16 = 256 = $100

2 x 16 = 32 = $ 20

3 x 16 = 48 = $ 30

4 x 16 = 64 = $ 40

5 x 16 = 80 = $ 50

6 x 16 = 96 = $ 60

7 x 16 = 112 = $ 70

8 x 16 = 128 = $ 80

9 x 16 = 144 = $ 90

10 x 16 = 160 = $ A0

11 x 16 = 176 = $ B0

12 x 16 = 192 = $ C0

13 x 16 = 208 = $ D0

14 x 16 = 224 = $ E0

15 x 16 = 240 = $ F0

16 x 16 = 256 = $100

Most people tend to use the $ symbol to indicate that the digits which follow are in *hexadecimal* form. There are several other ways to show the same thing. Here are some of the representations which you may come across (Note: nn represents the hexadecimal digits):

**$**nn

nn**H**

nn**h**

**&H**nn

**&h**nn

&nn

nn_{16}

nn

nn

&nn

nn

Protect & survive - Hard disk care |

PC Notes |

When Is A Computer? |

PC Notes |

Amiga Notes |

Atari Notes |

Power Dressing - The PowerPC |

Apple Notes |

ST Notes |

Software Support - Hints, Tips & News From The World of Music Software |

Atari Notes |

Editing on the Model 64 |

Browse by Topic:

The contents of this magazine are re-published here with the kind permission of SOS Publications Ltd.

*Feature
by Martin Russ*

Previous article in this issue:

Next article in this issue:

mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.

If you value this resource, you can support this project - it really helps!

*New issues that have been donated or scanned for us this month.*

*All donations and support are gratefully appreciated - thank you.*

*Do you have any of these magazine issues?*

*If so, and you can donate, lend or scan them to help complete our archive, please get in touch via the Contribute page - thanks!*