Understanding Hex

Mark Mansur, http://www.tunerpro.net/

Introduction

Hexidecimal seems to be a mystical topic to a good portion of beginners in the DIY-EFI community. I hope to clear up the concept as simply as possible with this short paper.

Decimal and Base-10

If you can read this paper theres a good chance you can also count. When we count in our every-day world, we count in decimal. The "geek" term for decimal is Base-10. What it means is that we use 10 different, unique, digits as building blocks to form numbers (all numbers). For the sake of clarity, I'll list the base-10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

Hexidecimal and Base-16

So what exactly is hexidecimal? Well, its base-16 (Hex means 6 and dec means 10. Look: 6 + 10 = 16)! And from what I told you about base-10, you sharper readers may have deduced that it means we use 16 different, unique digits to form numbers (all numbers). Again, for clarity, I'll list the base-16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

What's with the letters?

In every-day counting we are familiar with digits 0-9. But what if we wanted more numeric "building blocks" with which we could create numbers? We would have to invent 6 more digits. Having an alphabet at our disposal makes this easy. We'll borrow letters!. A is the 10th digit, B is the 11th digit, etc, ending with F as the 15th digit.

Ones, Tens, Hundreds, and Ones, Sixteens, and Two-Fifty-Sixes!

When we count from 0, what do we do when we run out of digits in the ones column? We increment the number in the tens column and start again from zero in the ones column! Example: counting from 9 to 10, or 19 to 20, or 29 to 30, etc. This is a familiar concept to everyone reading this, I'm sure.

What happens when count in hex from 0 and we run out of digits in the ones column? Similar to decimal, we increment the number in the sixteens column and start again from zero in the ones column! Example: counting from F to 10, 1F to 20, 2F to 30, etc. This may still seem a little strange. Read on.

I still don't understand. Explain it a different way. Please?

Follow me for a second. Lets say every month in the year had exactly 30 days, no more, no less. We'll start on January 1st (1/1). Now we count to January 30th (1/30). What day comes next? "Easy!" you say... February 1st (2/1)!

When we continue to walk through the days and get to February 30th (remembering all of our months have 30 days), what day comes next? March 1st (3/1)!

Guess what, if you can follow that, you can count in base-30!

"What?" you say? Well, before we incremented the month, we counted through all of the days. When we ran out of days in the month, we incremented the month and start the day count over again!

Hex is the same conceptually, only we count in 16's instead of 30's. The only difference is that we use letters A - F for 10th - 15th digits (remember that digits are the building blocks for expressing numbers). For the sake of clarity, I'll list the first 32 decimal numbers and their corresponding hexidecimal digits for you. I'll highlight where we run out of digits and therefore increment the next digit column for each:

Dec
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F
20

Tools for counting high

I personally use hex almost every day of my life. Even so, if you asked me, "Quick! Using only your brain, what is the decimal number 13503 converted to its hex equivelant?" I'd look at you and make a remark like, "if only was that smart, I could rule the world!"

I use the Windows calculator for converting decimal values to their hex equivelant and hex values to their decimal equivelant. Try it! Open the calculator (in the start menu, programs, accessories - or some of you may have a shortcut on your keyboard) and make sure "Scientific" is checked in the view menu. While the "dec" radio button is selected, enter a decimal number and then click the "hex" radio button. The hex equivelant of the decimal number you entered will be displayed! Try it backwards - while "hex" is selected, enter an arbitrary hex number (can't think of one? Try: 1A) and then click the "dec" radio button. The decimal equivelant is displayed (if you used my example, you'll get 26 as the decimal equivelant ... look in the table above!).

Does this have something to do with $ and 0x?

Ever wonder why people always talk about money when discussing code? $32 this and $6E that?! The $ symbol means the number is a hexidecimal number and not a decimal number. Why use a symbol? Becuase if I wrote 32 all by itself you would have no way of knowing whether I meant decimal 32 or hex 32 (hex 32 is 50 in decimal - I know this because I used the windows calculator). In some computer languages '0x' is placed in front of the number to signify hex: 0x32.

Conclusion

Hex is your friend. Get to know it. It's worth it.

 
Copyright 2002 - 2013 Mark Mansur