Hexadecimal (Base 16) - or Hex
What a misnomer this is !! There is nothing decimal about this at all, except for the fact that they ran out of digits. This is the base 16 numbering system. Decimal is the base 10 numbering system. From now on, whenever you see "Hexadecimal" - forget about the decimal system completely, and just think base 16.
- each byte is shown as a pair of nibbles (4 bits), or two digits, for example D7 is one byte of binary Base2 data shown in Base16 (Hex)
- each pair of digits is separated by a space, for example, E3 42 8B 03 DD F2
OK, So why Did they Call it That ?? Base 16 requires 16 unique digits. Since in base 10, we use the digits 0 through 9, six additional digits were needed. Rather than use some new hieroglyphics to represent the last 6 digits, it was decided to use letters (A through F). There was no Latin designation for 16. Oh sure, we had uni, bi, tri, quad, pent etc. - but it stops at dec (10) I believe. Now, decimal gives us ten digits, and a hexagon is a polygon with 6 sides - so they combined the terms, and came up with "Hexadecimal". To call it "Hex" for short is fine, but a bit misleading - since you need the combination of Decimal and Hex to get all 16 digits.
Hex -the Perfect Representation of bytes - Hexadecimal represents bytes perfectly, since two Hexadecimal digits is exactly equal to one byte, or 8 bits. Our decimal system cannot do that. one byte goes from 00000000 to 1111111. In hex one byte goes from 00 to FF. In decimal, one byte goes from 0 to 255. You can see why it is difficult to use decimal values to represent binary values. Hence the popularity of Hex. Let me explain . . .
Remember that in any base system, each place's weight increases by a power of 1, so that for the first 4 places with base 16:
Place |
3 |
2 |
1 |
0 |
weight (16 raised to that power) |
1536 |
256 |
16 |
1 |
So, in base 16, or Hex, the number C7D3 hex = 12x1536 + 7x256 + 13x16 + 3x1 = 18432 + 1792 + 208 + 3 = 20,435 dec
NOTE: for hexadecimal notation, quite often an "x" or a "0x" or simply an "h" precedes the number. 0x is the most common. When you see this, just lop off the 0x in front and then you have the actual hex value.
Really huge numbers, right? Well, don't worry, as you will soon see, Hex allows us to break huge binary numbers down to pairs of Hexadecimal numbers. Hex is used to designate huge memory spaces with millions of bytes, but since we look at it in pairs typically, 0xFD0000 is a common memory address, but if you converted it to decimal, the number would be huge. Hex allows us to represent huge numbers with less digits.
The counting upwards of hex is also much simpler than binary, as you will see in the conversion table below.
Hexadecimal
makes binary numbers manageable to Humans
In fact, the only think we will be using Hex for - is to represent bytes, which have a maximum value of 255, which is FF ( FF = 15x16 + 15x1 = 240 + 15 = 255 ). Often more than one byte at a time will be involved, but that only means that the Hex numbers will be used in pairs. On pair of hex numbers can represent one byte.
Conversion Table - in following our discussion earlier about the base of numbering systems, a base 16 system would equate numerically as follows (using decimal and binary equivalents so that you can understand the values) :
| Decimal | Hexadecimal | Binary |
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Right away, you can see that we can use the full range of possible hex digits to represent all the possible states in one "nibble" (1/2 of a byte, or 4 bits). Therefore, a byte can be displayed using two Hex digits - for example :
11000101 = 1100 0101 binary = C5 hex
We had better double-check that. Let's translate both number to decimal to make sure they match :
11000101 = 128 + 64 + 4 + 1 = 197
0xC5 (which means "hex C5")= 12x16 + 5x1 = 192 + 5 = 197
You can see the difficulty in reading bytes as 11010110, etc. The PC hardware has no trouble processing that information, but we, as humans, have no intuitive, quick way of determining the value of a byte when given as a string of 8 bits. The beauty of Hex, is that it allowed humans and even computer screens to display binary values in hex. Of course, it is still not exactly intuitive, but people that use hex frequently, become fluid with it.
Dotted Decimal Notation - this is being mentioned here - just to insure that it is not confused with hexadecimal. With the advent of the internet, 4-byte IP (Internet Protocol) addresses were used, with "dotted-decimal notation". Since PC's and routers, servers, etc., use the binary system - they needed an binary addressing system. But since people feel much more comfortable using the decimal system, it was best to show these binary addresses as decimals.
They took the 4 bytes, converted them to decimal numbers, and placed dots in between. For example, the address :
192.205.37.69 (dotted decimal notation) = C0 CD 25 45 hex
Hex representation of IP addresses is rare - but note that with Hexadecimal representation of IP addresses , the dots are not used. Sometimes, rarely, to show how subnetting works (logical operations are performed on a bit-by-bit basis) the address is written out as binary, with all 32 bits shown, and a space between each byte.