Hexadecimal by Lazy Bastard
Hexadecimal is the numerical system that most hacking platforms work in. Therefore, it is very useful to have a basic understanding of hex, as it is commonly called.
The system we use in our everyday lives is called the decimal system. Its digits are from 0 to 9. In the hexadecimal system, the digits go from 0 to F. There are ten digits (counting 0) in the decimal system: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. In hexadecimal, there are 16 (counting 0): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. You can see that A represents 10, and, by counting, that F represents 15.
-Can I have a complete hexadecimal/decimal conversion chart?
No. Heheh. In order for me to make one, I would have to type in 65,535 different combinations and their decimal equivalents, and that's only to FFFF. I will, however, give you a chart which should, if you pay attention, easily suffice; hexadecimal on the left, decimal on the right.
Now let's look at some combinations of high hexadecimal numbers...
You will use this chart further on in this FAQ, so take a good look at it and make sure you at least have a basic understanding of it.
-Are there any basic rules in hex?
There are quite a few, as in any numbering system. I will explain only two which I have found useful here. First, any decimal (our system, as I've said) number that is divisible by 16 (meaning it can be divided by 16 and come out with a whole number) can be easily converted to hex. Simply divide that number by 16, then multiply by 10. Here is an example:
I have 64, and want to know what 64 is in hexadecimal.
64 divided by 16 = 4
4 X 10 = 40
64 in hex is 40.
Understand? Hopefully, because I'm moving on to another one, heheh. If you want to add a zero to a number in hexadecimal, for example 10 hex, making it (in this example) 100 hex, and determine its new decimal equivalent (assuming, of course, you know the decimal equivalent of the original number), you DO NOT multiply the decimal equivalent by ten, as in our system. The reason you multiply by ten in our system is that in our system, there are ten individual digits, 0-9. In hex, there are 16, 0-F, therefore you must multiply by 16.
16 X 16 = 256
Therefore, 100 hex = 256 dec
Here's another example:
3B = 59
3B0 = ?
To find the decimal equivalent of 3B0, you must multiply the decimal equivalent of 3B by 16.
59 X 16 = 944
Therefore, the decimal equivalent of 3B0 is 944.
-How do I add in hex?
To add in hex, simply add in hex, heheh. Here's an example:
B + 7 = 12
Look at the chart. This is because B = 11 in decimal, and 7 obviously = 7 in decimal, and 11 + 7 = 18, which in hex is 12. Here's another example:
5 + 4 = 9
This is simple math; nothing is any different here than what the teacher taught you in kindergarten.
-How do I add larger numbers in hex?
There are two ways I know of (that are feasible) to manually add in hex with large numbers. There are, I'm sure, a few others, but they are far too complicated to ever have any desire to use, especially when you'll get the same answer using these. Say our numbers are 35B and 64C, and we wish to add them together. Here are the two ways we could do that:
-The hard way
Using this method, you will first find the decimal equivalent of each hexadecimal number (use your chart), in this case the decimal equivalent of 35B and 64C. To do this, start by finding the decimal equivalent of the first digit of the first number. In this example,the first number is 35B, and the first digit of it is 300.
300 in decimal = 768
Next, find the equivalent of the second digit, 50.
50 in decimal = 80
Finally, find the equivalent of the last digit, B.
B in decimal = 11
Now, add them all (the equivalents) up.
768 + 80 + 11 = 859
Therefore, 35B hex = 859 decimal.
Next, move on to the second number, 64C. Start with the first digit, as always.
600 in decimal = 1536
Next, as always, the second digit.
40 in decimal = 64
Finally as always, the last digit.
C in decimal = 12
Now (as always, heh), add all the equivalents together.
1536 + 64 + 12 = 1612
Now add both sums together.
859 + 1612 = 2471
Now you must find the hexadecimal equivalent of 2471. The easiest way to go about doing this is to use the chart.
You know that 900 in hex = 2304, which is lower than 2471. And A00 in hex = 2506, which is higher than 2471. Therefore, the hex equivalent of 2471 is somewhere between 900 and A00. Now, find the difference between 2471 and the number below it that is the closest number to it that you know of; in this case 2304 (from 900).
2471 - 2304 = 167
167 in hex = A7 (use your chart and some simple addition)
Now add A7 to the hex version of the number below 2471 (2304), which is 900.
900 + A7 = 9A7
And there's your answer.
35B + 64C = 9A7
-The easy way
Simply break down each number by digit, staying in hex for the entire problem, 35B on the left, 64C on the right, and add the individual digits together as I have done below.
300 + 600 = 900
50 + 40 = 90
B + C = 17
Then add the three sums together.
900 + 90 + 17 = 9A7
If you do not see why, look at your chart, and I'll explain as best I can.
900 + 90 = 990
90 + 17 = A7
900 + A7 = 9A7
-Is there a basic formula for conversion, so that I might understand why _ in hex = _ in dec?
Yes, actually, there is, as there must be for it to be a real numbering system coexisting parallel to decimal.
I discovered, while studying binary numbers and their conversion to decimal counterparts, that the same system of equations, representing place values and the numerals occupying them, that is used to convert binary to decimal, would work with not only conversion between any other numbering systems, but also, and obviously, with any numbering system by itself. Here is a quick explanation, in decimal:
The decimal number 1234 represents not only a finite number of theoretical objects (discounting a host of other possibilities of its representation), but it also represents an equation. It is as follows (^ represents exponentiation, as in "Squared, to the third power", etc, and remember that any number to the 0th power is 1):
(1 x 10^3) + (2 x 10^2) + (3 x 10^1) + (4 x 10^0) =
(1000) + (200) + (30) + (4) = 1234
Here's another example:
(5 x 10^2) + (6 x 10^1) + (7 x 10^0) =
(500) + (60) + (7) = 567
The reason that the number is multiplied by an increasing power of ten is that decimal is ten-base. Were it sixteen-base, as hexadecimal is, you would multiply by an increasing power of 16. Now, for this next part you might have to stretch your mind a little, unless you're like me and enjoy wierd, abstract ideas. The reason for the exact exponent of ten that you may observe, for example, in the number 567 (look up, if you've forgotten already, heh), is as follows:
The number 7 is in the ones place. 10 (along with ANY other number) to the 0th power is 1. The number 60 is in the tens place. 10 to the 1st power is in the tens place. Finally, the number 500 is in the hundreds place. 10 to the 2nd power is in the hundreds place. Now you see a pattern, and now I realize that I was wrong; you didn't have to stretch your mind, heheh. Now that you hopefully understand how this system works, I'll move on to the actual use of it. This is where you have to use your new-found (or not) knowledge of hex to understand. Let us take the hex number FEDC, and convert it to dec using simple knowledge of conversions of single-digit numbers between hex and dec. Pay attention to everything here, and remember that 10 hex = 16 dec:
hex- (F x 10^3) + (E x 10^2) + (D x 10^1) + (C x 10^0) =
dec- (15 x 16^3) + (14 x 16^2) + (13 x 16^1) + (12 x 16^0) =