Tell you what, here's a writeup on hexadecimal (or hex) that's actually useful.

Everything you always wanted to know about hex but..

No, scratch that, it's far too bad a pun. M'kay, try again..

FryingLizard's Useful Guide To Hex (and Binary, along the way)

As you know, hex is used by geeks to specify numbers. It's useful because it is (a) compact to write/type, and (b) relates closely to binary, which is what computers are all about.

How it works

Numbers that are in hex are usually indicated by either a '$' prefix (general use), a '0x' prefix (common - used in C and other programming languages), a '&' prefix (archaic, used on some 8-bit computers), or, occasionally, the letter 'H' on the end. So, you could see hex numbers written as $1234, 0x1234, &1234, or 1234H.

A hex digit can go from 0 to 15, and as the familiar decimal system runs out at '9', we have to cheat and start using letters to represent values from 10 to 15, so we use A-F.

So, the hex number $F is '15' in decimal, $9 is just plain '9' in decimal, and $10 is '16' in decimal...
Why? Well, obviously in decimal the number '10' means 'one times 10 plus zero'. Because hex goes up to 15, '$10' means 'one times 16 plus zero'. Hence, $18 is 'one times 16 plus eight', or 24.

If you follow on from this, $100 is 'one times 16 times 16, plus zero times 16, plus zero', or 16*16, which = 256.

It can be helpful to memorise (well, it just kinda sinks in after a while) the following;
$10=16, $100=256, $1000=4096 (16*16*16), $10000=65536, and so on.
So, $FFFF (in at the deep end) is actually 65535, because it's one less than $10000, or of course you could work it out the long way, as ($F=15, so 15*4096 + 15*256 + 15*16 + 15 = 65535)

Why do we bother? Are we just hopeless geeks?

Well, because, like I said earlier, hex is actually fairly closely related to binary.
In binary the only numbers are 1 and 0, and this is all computers really, deep down, understand - this is because all the little wires inside your computer can only be in two possible states - 'voltage going down the wire' or 'no voltage going down the wire', i.e. 1 or 0.

Binary numbers are usually notated by a '%' prefix, so %1 is just 1, %10 is 2 (1 times 2, plus 0), %1000 is 8 (1 times 2*2*2), and so on. Thing is, binary numbers are a pain in the arse to deal with, because they get pretty long, for example 12345678 is %101111000110000101001110, which clearly sucks fairly badly.

M'kay, so binary is too cumbersome, why is hex better?

Well, because hex - also known as base 16 (because the numbers go from 0 to 15; 16 possible values) - is based on a power of two (2*2*2*2 or 24),
and binary is powers of two, so in fact a single hex digit directly corresponds to four binary digits. (by the way, binary digits = bits)
The number 10 in decimal is $A in hex, and %1010 (1 times 2*2*2 plus 1 times 2 = 8 + 2 = 10) in binary, $F in hex = %1111, so $F0 in hex is %11110000. M'kay?

If you treat each hex digit as directly being equal to 4 bits (4 bits is called a nibble, by the way, same as 8 bits is called a byte) you can see that hex is just a nice compact way of handling the binary numbers that make the computer run.

For if a computer uses 8 physical wires together (called a bus) to represent a number, you have 8 bits, so you can represent a number from %00000000 (0) to %11111111 (255) over those 8 wires. As you can see '255' isn't exactly an intuitive number because we're using decimal, but %11111111 is $FF in hex, which fits far more nicely.
It gets far worse when the numbers get larger; %1111111100000000 is '65280' in decimal, but a nice clean $FF00 in hex.

If you want to convert %1010000010100000 into decimal it's a pain in the arse (it's 41120, by the way), but converting it to hex is relatively easy - you just break the binary number into sets of 4 bits and away you go - remember that %1010 is 'A', so you get $A0A0.

By the way, although geeks like me are fairly good at converting between hex and decimal in our heads (you just get used to it after a while), most sane people use a calculator (e.g. the Windows calculator in 'scientific' mode will do it).

Hope this helps!

Love,
FryingLizard

Hexadecimal is one of the villains on the TV show Reboot. She is the sister of the virus Megabyte, and a virus herself. However, Hexadecimal is as different from her greedy, purple, control-freak brother as granola is from motor oil.

Imagine Mr. Mxyzptlk from the old Superman comics crossed with Kodachi Kunou from Ranma 1/2, and you'll have Hex in a nutshell, emphasis on nut. Hexadecimal is utterly chaotic in every sense of the word. She also posseses incredible reality-altering powers. She once turned everyone in the "city" of Mainframe into stone (except for herself and Bob), but after Bob pointed out that Hex had made the whole city static and boring, Hex promply reversed what she had done *with a snap of her fingers*! And that's just a sample. If she wanted to, she could probably level the whole city, but what fun would that be? She also seems to develop an infatuation with Bob that borders on obsessive as the series progresses.

hex = H = hexit

hexadecimal n.

Base 16. Coined in the early 1950s to replace earlier `sexadecimal', which was too racy and amusing for stuffy IBM, and later adopted by the rest of the industry.

Actually, neither term is etymologically pure. If we take `binary' to be paradigmatic, the most etymologically correct term for base 10, for example, is `denary', which comes from `deni' (ten at a time, ten each), a Latin `distributive' number; the corresponding term for base-16 would be something like `sendenary'. "Decimal" comes from the combining root of `decem', Latin for 10. If wish to create a truly analogous word for base 16, we should start with `sedecim', Latin for 16. Ergo, `sedecimal' is the word that would have been created by a Latin scholar. The `sexa-' prefix is Latin but incorrect in this context, and `hexa-' is Greek. The word `octal' is similarly incorrect; a correct form would be `octaval' (to go with decimal), or `octonary' (to go with binary). If anyone ever implements a base-3 computer, computer scientists will be faced with the unprecedented dilemma of a choice between two correct forms; both `ternary' and `trinary' have a claim to this throne.

--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.

The hexadecimal number system has 16 digits:

    Hex digit: 0 1 2 3 4 5 6 7 8 9  A  B  C  D  E  F
Decimal value: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

To figure the decimal value of a hexadecimal number:
Step 1:Let N equal the value of the leftmost hex digit. Cross out this hex digit.
Step 2:If there are no hex digits left, STOP. The result is the current value of N.
Step 3:Increase N by a factor of 16. (Why 16? Hexadecimal is base 16)
Step 4:Increase N by the value of the leftmost hex digit. Cross out this hex digit.
Step 5:Go to Step 2.

Example: Convert 0xD5C0 to decimal.

The "0x" at the beginning is not part of the number. It just means that what follows is a number in hexadecimal.

  Hex     Value
digits     of N    Step   Explanation
------   -------   ----   -----------------------------
 D5C0                     START
  5C0        13      1    Value of D is 13,
                            Crossed out D, set N=13
  5C0        13      2    Keep going
  5C0       208      3    13*16=208, set N=208
   C0       213      4    208+5=213,
                            Crossed out 5, set N=213
   C0       213      5    Go to step 2
   C0       213      2    Keep going
   C0      3408      3    213*16=3408, set N=3408
    0      3420      4    Value of C is 12, 3408+12=3420
                            Crossed out C, set N=3420
    0      3420      5    Go to step 2
    0      3420      2    Keep going
    0     54720      3    3420*16=54720, set N=54720
          54720      4    54720+0=54720
                            Crossed out 0, N still is 54720
          54720      5    Go to step 2
          54720      2    STOP. Result = 54720.

However, if it is just a 2-digit hex number, the formula is VERY easy: ((first digit) * 16) + (second digit)
Examples:
0x37 = 3*16+7 = 55
0x8F = 8*16+15 = 143 (Remember, F in hex means fifteen. See table of hex digits.)

Hexadecimal is often used because numbers in computing come out even in hexadecimal more often than in decimal.

1 kilobyte = 1,024 bytes = 0x400 bytes
1 megabyte = 1,048,576 bytes = 0x100000 bytes

Hexadecimal is often used in reference to the RGB color code.

On a seven segment display the hexadecimal characters can be displayed thusly:

 _      _   _       _   _   _   _   _   _              _   _ 
| |  |  _|  _| |_| |_  |_    | |_| |_| |_| |_   _  _| |_  |_ 
|_|  | |_   _|   |  _| |_|   | |_|  _| | | |_| |_ |_| |_  |  

Simple enough, eh?

I once ran across a microcomputer training manual, (If memory serves, it was distributed by Ampex.) that claimed the correct way to display the hexadecimal characters was as follows:

 _      _   _       _   _   _   _   _              _        
| |  |  _|  _| |_| |_  |_    | |_| |_| |_   _  _| |_ |_|   |
|_|  | |_   _|   |  _| |_|   | |_| | | |_| |_ |_| |  | | |_|

The explanation was that this eliminated the possibility of confusion when viewing an inverted display. I dismissed this as unique and amusing lore, until I encountered a customized Control Data Corporation, FDS disk drive. I needed to change a parameter on the drive and watched with amusement as I pushed the increment button and the display skipped `9' and `E' and didn't `roll over' until it incremented past `J'! Now, given that this was a 200lb. disk drive mounted in a rack, (with very specific instructions on the need for the unit to remain level during operation), I am at a loss to explain the need for this type of display. I have never seen such a display since, nor sadly, have I been able to track down that training manual again.

Log in or register to write something here or to contact authors.