Oh God. HEX! It’s just so hard to get your head around. A lot of people think that getting into programming means they’re going to have to learn how to speak “computer” by learning binary and write programs with it. When you get into it, there are very few times that you’ll actually need to use binary for every day tasks. Much more common however is Hexadecimal or Base16.
I’m going to try to give you a rundown on Hexadecimal and while I’m at it, I’ll swing back around to binary with what we’ve learned with Hex.
Our common numbering system that we use day to day is actually called base10 or Decimal. Each digit has 10 positions, zero to nine. if I post up a number like 38 the number in the right most is 8 which means there are, well, 8 in the “ones”
location. “Ones” is not a good thing to call this, because, as we’ll learn, that can change. It’s more accurate to call this the least significant digit or LSD for short. That means it’s the position that affects the overall number the least.
Numbers in this position have the least overall value. Consider the digits of our example.
8 digit may be larger than the
3 but it’s value is also affected by it’s position in the digit.
8 but the
3 means there are
30. In English, we call this Thirty Eight but in a lot of other languages it’s called Thirty and Eight. This is the mindset you want to get into. Don’t
think of numbers as individual values, rather think of them as a combinations of digit values. In base 10, each digit above the LSD is a value of
10 of the digit immediately preceding it.
10 is worth
30 is 3 times
100 is worth
10 is what’s important in base10. It informs when the number rolls over into the next digit.
Hexadecimal is also known as base16. In Hex,
1 in base10, our well known number system. In fact 0-9 is the same in Hex and Decimal. but those are the only numbers that are the same. For instance.
10 in Hexadecimal is actually
16 in base10. But how does this happen? Well in Hexadecimal, there are single digit numbers that are higher than
9. How though? You can’t just invent numbers like that. Well actually you
can. Base10 is just a way to record numbers. There’s no reason we couldn’t record numbers another way. Math gets different in different numbering systems but we’re not too worried about that, we just want to be able to record the same information
in less space. Hexadecimal’s LSD is recorded 0-15 like so.
Letters! Ok so, once you’ve gotten your head around that you can understand how
F + 1 = 10 is the same as
15 + 1 = 16 then you have to start thinking about how
20 in hex is actually
Now we get to the last part you have to understand about base16. Remember how we said that
10s? Well in base 16,
16s. So in this example,
FF + 1 = 100 and
100 in hex is
256. This is the basics of every numbering system. the
base part of base16 means how many positions the LSD can be in before overflowing into the next digit. Binary is no different.
Binary is also called base2.
Knowing what we know in Hexadecimal, Binary should be more approachable. We don’t need to make up new digits because
1 already exist.
take a look at this.
For a large margin all you’ll need to know about Hexadecimal will be 2 digits.
FF is usually the max number you’ll encounter because it just so happens to be a full byte of data. a byte is 8 bits. A bit is a single digit of a
FF == 255 == 11111111
This is a quick rundown of these numbering systems. To be completely honest, I’m still trying to get my head wrapped around it. The point is here, don’t be intimidated. It’s just a different way to store values in a more compact way, If I
have 1000 entries of 255, I’d much rather store two
FFs than three digits
255 2000 digits vs 3000 digits. More memory, more space.
If you have anything to add, or any questions, Drop me a line.