Hexadecimal CodeReference > Mathematics > Codes and Secret Messages
Computers "think" in Binary code, or Base Two. But that is very hard for humans to read, so computer programmers have a special code they use when talking to computers; it's called Hexadecimal Code. It's easier to read than Binary code, but a whole lot harder to read than English! As computers get more sophisticated, we programmers use hexadecimal less and less, but we still use it sometimes. For instance, I wanted to color this page dark purple, I wouldn't tell the computer to paint it "dark purple", I would tell the computer to paint it "#440044", and the computer understood exactly what I meant (see the link about colors at the bottom of this page for more information about encoding colors).
Sometimes we use different symbols sometimes to indicate that we're talking to a computer in hexadecimal. Sometimes we put a pound sign (#) in front of the code, and sometimes we put an ampersand followed by an H (&H). It's kind of like if you were talking to a friend in Pig Latin, before you started, you might say to him "I'm going to talk in Pig Latin now", just so he'd know what you're doing. Well, that's what we're doing when we put a "#" or a "&H" in front of hexadecimal code. Since the computer doesn't normally speak hexadecimal, we're really just saying, "Hello computer, I thought you should know, I'm going to talk to you in hexadecimal now!"
So how does hexadecimal work? Well, hexadecimal is the same as Base Sixteen. Normally we count in what's called Base Ten, and we probably do that because we only have ten fingers. In base ten, we have ten digits - 0 through 9. In fact, sometimes we refer to our fingers as digits!
So imagine you had sixteen fingers instead of just ten. Wouldn't that be WILD! Well, if you had sixteen fingers, you'd count in base sixteen, which is hexadecimal. But to do that, you'd need sixteen digits. 0 through 9, but then we still need six more digits! Hmmm... I know! We'll call the other digits A, B, C, D, E, and F.
That can be a little confusing, because now when we write numbers in hexadecimal, they can actually have LETTERS in them! But you get used to it after awhile. Take a look at how these numbers look in hexadecimal:
10 = #A, 11 = #B, 12 = #C, 13 = #D, 14 = #E, 15 = #F
16 = #10, 17 = #11, 18 = #12
How do you convert any number to hexadecimal? Well, let's take an example. Let's start with the number 16,325. To begin, we need to find the largest power of 16 that's less than that number.
161 = 16
162 = 256
163 = 4096
164 = 65,536
Ah hah! 163 (4096) is what we're looking for. Now we ask the question: How many times does 4096 go into 16,325? And the answer is: 3. With a remainder of 4037. The first digit of our hexadecimal number is going to be 3, and we need to do some more work with the remainder.
How many times does 256 go into 4037? (256 is 162, remember) The answer is 15, with a remainder of 197. So, our next digit is a 15. WAIT A MINUTE! 15 isn't a digit! That's right. But look up above at my list of hexadecimal numbers, and you see that whenever we have a 15, we can call it F. (Are you confused yet?) Now our first two digits of our hexadecimal number are 3 and F. And we still have a remainder of 197 to deal with. Shall we keep going? Or have you had enough?
Well, if you're still reading, next we need to take that 197 and divide it by 16. We get 12, with a remainder of 5. How do we write a 12 in hexadecimal? It's a C. Right...so far our digits are 3, F, and C. And now we're left with a remainder of 5, and there are no more powers of 16 to divide it by, so I guess we'll just have to tack it on the end...
So our final base sixteen (hexadecimal) number is:3FC5
Seems a little confusing, doesn't it! But did you know that your calculator may have a command to convert regular numbers into hexadecimal? You should check it out!
So how could you use hexadecimal to make a secret message? Well, every letter in the alphabet has a number assigned to it, and you could just convert that number into base sixteen. For example, the letter 'Z' is number 90, and if you converted that to base sixteen, you would have '5A'.
Now that you know a little bit about how hexadecimal code works, go ahead and type a message in the encoder, and see what it looks like!
For more information about encoding values, please visit the following link: