Learning About Computers and the Internet
Tips Blog WinXP Internet Computing Downloads Vista/7 Home

Hexadecimal Numbers Explained

The hexadecimal number system is used throughout computing. This article explains what it is.


 As almost anyone who uses a computer is at least dimly aware, the actual operations of a computer are done with a binary number system. Traditionally, the two possible states for a binary system are represented by the digits for “zero” and “one” although “off” and “on” or sometimes “no” and yes” are closer to what is actually involved. Most of the time a typical PC user has no need to think about this aspect of computers, but every now and then the underlying binary nature will manifest itself. Actually it is a more compact variant of the binary system, called hexadecimal (or “hex” for short) that is likely to be encountered. Since many computer users are totally baffled when they see something written in hex, I am going to point out some of the aspects of this system so that it can be recognized when it is seen. Although interpreting the details of hex code is not of interest to many people, being able to recognize it will at least make computers less mysterious and intimidating. Just being able to say, “Oh yes, that’s hex”, is somehow comforting, even when you have no idea what it means.

What is Hexadecimal?

The reason hex is used in computing is for the convenience of humans since the computer really only understands pure binary. Hex is much more compact since it is based on 16 (the fourth power of 2) instead of 2. Pure binary numbers based on 2 can quickly become unwieldy to write. For example, the three-digit decimal number 513 requires ten digits in pure binary (1000000001) but only three (201) in hex. However, representing hex numbers requires sixteen distinct characters compared to the ten used in decimal notation. The sixteen characters that are used are the ten numeric symbols, 0-9, and the first six letters of the alphabet, A-F. The letters are often, but not always, capitalized. Thus, the first ten numbers 0-9 are written the same in both decimal and hex and the equivalents of the decimal numbers 10-15 are indicated by a single letter, ranging from A to F. Table 1 shows how the decimal numbers 10 -17 are written in hex.

Table 1. Some hex numbers
Decimal 10 11 12 13 14 15 16 17
Hex A B C D E F 10 11

Note that "10" and "11" in hex are not the same as "10" and "11" in decimal. Only the first ten numbers 0-9 are the same in the two representations. To get some feel for what hex numbers are like, let us look at some examples.  Consider the hex number "D8AF". To evaluate the hex number "D8AF", use exactly the same scheme that we use when we write decimal numbers. The various single digits in a decimal number are placeholders representing a multiple of a power of ten. Powers of ten ascend from right to left. For example, the decimal number "365" means 3x102 + 6x10 + 5. In hexadecimal each single character represents a multiple of a power of sixteen. Thus our hex number "D8AF" translated to decimal means 13x163 + 8x162 +10x16 +15 = 55471. Actually going through the arithmetic for hex numbers in order to evaluate them is not really necessary, however. The easier way is to use the calculator that comes as an accessory in Windows. It can convert between decimal and hex when in "Scientific" view.

Note that a hex number such as "365" is not the same as the decimal number "365." Its actual value in decimal terms is 3x162 +6x16 +5 = 869. To avoid confusion, hex numbers are often labeled or tagged so that their meaning is clear. One method of tagging hex numbers is to append a lower case "h" at the end. Another method of labeling, used in programming, is to precede the number with 0x. Thus, the hex number "D8AF" could also be written  "D8AFh", where the lower case "h" at the end is just a label to make sure we know it is a hex number. Or it might be written with a labeling prefix as "0xD8AF".

When Does the Average PC User Encounter Hex Numbers?

By convention, addresses of locations in RAM are given in hex. Thus, functions involving memory in RAM use hex to designate specific locations. For example, input/output functions may be assigned a fixed location in RAM and you can see these hex addresses in Device Manager or other system accessories.

Standard Windows error messages may include hex addresses. For example, a common type of error message is the "Fatal exception". The message will contain a statement," A fatal exception <hh> has occurred at <xxxx:xxxxxxxx>", where <hh> stands for some two character hex code that identifies the type of error and the x's are a hex location in memory. An example is "Fatal exception 0E has occurred at 0028:C00082CD." Here "0E" indicates the hex number "zero-E" (not Outlook Express), which means error 14, a page fault. These addresses aren't much help to a typical PC user but may on some occasions be useful to a technician if you are on the phone trying to get help. There is a useful compendium of Windows error messages with various hex addresses at http://aumha.org/kberrmsg.htm. The hex addresses may help pinpoint the source of trouble.

Now that we have to worry about "activation" in Windows XP, it is worth knowing that some networking components have a unique identification number in hex, sometimes called a MAC (media access control) number, that is part of the way XP defines your activation code. Other kinds of hardware also may have unique ID numbers in hex. These unique identifiers all go into the activation code that Windows XP uses to recognize a specific PC.

Colors on Web Pages

Another place where hex numbers commonly occur is in HTML code where they are used to designate colors. Six characters are used, two for each of the primary colors red, green, and blue. The character "#" is used as an identifying label. Pure red is indicated by #FF0000, pure green by # 00FF00, and pure blue by # 0000FF. By blending various amounts of these primary colors, a large number of shades and colors can be generated. For example, royal blue is indicated by  #4169E1. For those who are interested, one of the many sites with tables of color codes is at http://www.december.com/html/spec/color.html. If you want to have a little fun playing with colors, open a new, blank file in Notepad (or other text editor). Enter the following line
      <body bgcolor=#ff0000></body>
and save the file with the extension HTM. Make sure not to save as a TXT file. Then double-click to open with your default browser. Now repeat the process with different color codes.

Web addresses

Spammers sometimes use hex to obfuscate their addresses. Or Web sites may use hex in the addresses of their files or secondary pages for security or other reasons. Did you ever see one of those long and complicated URLs that seem to make no sense in your browser's address bar? An interesting article on obscuring addresses is at http://www.pc-help.org/obscure.htm. Not all the methods mentioned in that article work in the newest versions of browsers since some of the "dotless" forms are no longer recognized. However, one method of writing addresses in hex that is still frequently used replaces the usual characters in an address with the hex for the ASCII code for the characters. Remember that at heart computers know nothing about letters or any other character. Everything has to be translated to binary. A standard code for all the common characters is one called ASCII  (from American Standard Code for Information Interchange). In an URL or Internet address, the hex equivalent of a character can be used by preceding it with "%" (without quotes). The URL www.vlaurie.com can be rewritten as

      %77%77%77%2E%76%6C%61%75%72%105%101%2E%63%6F%6D

Try entering it in your browser (may not work in AOL). The hex number following each percent sign is the ASCII code for a single character. For example, the hex code for "w" is "77" and the hex code for a period is "2E". Thus "www." becomes "%77%77%77%2E". The ASCII codes are given in many places but one reference is http://www.jimprice.com/jim-asc.htm. You can use tables to translate hex-encoded URLS but it is easier to use a converter such as Karen Kenworthy's "URL Discombobulator", which is available for free download at http://www.karenware.com/powertools/ptlookup.asp.


 << Home page ©2002-2014 Victor Laurie    Home page >>