In mathematics and computer science, base-, hexadecimal, or simply hex, is a numeral system with a radix or base of 16 usually written using the symbols 0–9 and A–F or a–f. The current hexadecimal system was first introduced to the computing world in 1963 by IBM. An earlier version, using the digits 0–9 and u–z, was used by the Bendix G-15 computer, introduced in 1956.
For example, the decimal numeral 79 whose binary representation is 01001111 can be written as 4F in hexadecimal (4 = 0100, F = 1111). It was IBM that decided on the prefix of "hexa" rather than the proper Latin prefix of "sexa". The word "hexadecimal" is strange in that hexa is derived from the Greek έξι (hexi) for "six" and decimal is derived from the Latin for "tenth". It may have been derived from the Latin root, but Greek deka is so similar to the Latin decem that some would not consider this nomenclature inconsistent. An older term was the incorrect Latin-like "sexidecimal" (correct Latin is "sedecim" for 16), but that was changed because some people thought it too risqué, and it also had an alternative meaning of "base 60". However, the word "sexagesimal" (base 60) retains the prefix. The earlier Bendix documentation used the term "sexadecimal". Schwartzman notes: “Since "hexadecimal" is a rather long word, it is sometimes abbreviated "hex". The word "hexadecimal" is unusual because Greek and Latin elements are combined; the expected purely Latin form would be "sexadecimal", but then computer hackers would be tempted to shorten the word to "sex".” Donald Knuth has pointed out that the etymologically correct term is "senidenary", from the Latin term for "grouped by 16". (The terms "binary", "ternary" and "quaternary" are from the same Latin construction, and the etymologically correct term for "decimal" arithmetic should be "denary".)
Several years ago an alternate, unambiguous set of hexadecimal digits was proposed. (Cf. Hexadecimal time)
| Hex | Bin | Dec |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
In typeset text, the indication is often a subscripted suffix such as 5A316, 5A3SIXTEEN, or 5A3HEX.
In computer programming languages (which are nearly always plain text without such typographical distinctions as subscript and superscript) a wide variety of ways of marking hexadecimal numbers have appeared. These are also seen even in typeset text especially if that text relates to a programming language.
Some of the more common textual representations:
X'5A3' are sometimes seen; PL/I uses such notation.
There is no single agreed-upon standard, so all the above conventions are in use, sometimes even in the same paper. However, as they are quite unambiguous, little difficulty arises from this.
The most commonly used (or encountered) notations are the ones with a prefix "0x" or a subscript-base 16, for hex numbers. For example, both 0x2BAD and 2BAD16 represent the decimal number 11181 (or 1118110).
The choice of the letters A through F to represent the additional digits was not universal in the early history of computers. During the 1950s, some installations favored using the digits 0 through 5 with a macron to indicate the values 10-15. Users of Bendix computers used the letters U through Z.
A common use of hexadecimal numerals is found in HTML and CSS. They use hexadecimal notation (hex triplets) to specify colours on web pages; there is just the # symbol, not a separate symbol for "hexadecimal". Twenty-four-bit color is represented in the format #RRGGBB, where RR specifies the value of the Red component of the color, GG the Green component and BB the Blue component. For example, a shade of red that is (238,9,63) in decimal is coded as #EE093F. This syntax is borrowed from the X Window System.
Example of conversion from hexadecimal triplet to decimal triplet: Hexadecimal triplet: FFCF4B
Separate the triplets: FF CF 4B
Convert each hexadecimal value to a decimal number:
Hexadecimal triplet FFCF4B = Decimal triplet 255,207,75
Hexadecimal is used also in more generic computing, as the most commonly found form of expressing a guaranteeably human-readable string representation of a byte. All the possible values of a byte (256 values) can be represented using the hexadecimal system. Some people assume that using 8-bit ASCIIto represent the value of a byte should work, but it does not, because ASCII has some unprintable characters (also called control characters) and therefore is not good for this purpose.
In URLs, special characters can be coded hexadecimally, with a percent sign used to introduce each byte; e.g., http://en.wikipedia.org/wiki/Main%20Page
The canonical written form of numeric IPv6 addresses represents each group of 16 bits as a separate hexadecimal number, to ease reading and transcription of the 128-bit addresses.
Page numbers on teletext are hexadecimal, with available numbers being in the range of 100-8FF. However, page numbers with letters are only used for "hidden" and engineering pages.
In October 1996, Simon Plouffe, Peter Borwein and Jonathan Borwein created an equation that allows the nth digit of pi in hexadecimal to be calculated, without knowing all (or indeed any) of the previous digits. The equation is given by:
| 1/ 0x1 | 0x1 | 1/ 0x5 | 0x0.3 | 1/ 0x9 | 0x0.1C7 | 1/ 0xD | 0x0.13B | ||||
| 1/ 0x2 | 0x0.8 | 1/ 0x6 | 0x0.2A | 1/ 0xA | 0x0.19 | 1/ 0xE | 0x0.1249 | ||||
| 1/ 0x3 | 0x0.5 | 1/ 0x7 | 0x0.249 | 1/ 0xB | 0x0.1745D | 1/ 0xF | 0x0.1 | ||||
| 1/ 0x4 | 0x0.4 | 1/ 0x8 | 0x0.2 | 1/ 0xC | 0x0.15 | 1/ 0x10 | 0x0.1 |
Because the radix 16 is a square (42), hexadecimal fractions have an odd period much more often than decimal ones. Recurring decimals occur when the denominator in lowest terms has a prime factor not found in the radix. In the case of hexadecimal numbers, all fractions with denominators that are not a power of two will result in a recurring decimal.
Another example is the magic number in FAT Mach-O files and java programs, which is "CAFEBABE".
A Knuth reward check is one hexadecimal dollar, or $2.56.
The following table shows a joke in hexadecimal: 3x12=36 2x12=24 1x12=12 0x12=18
The first three are multiples of 12, while in the last one "0x12" in hex is 18.
0xdeadbeef is sometimes put into uninitialized memory.
Consider converting 11112 to base 10. Since each position in a binary (base 2) number can only be either a 1 or 0, its value may be easily determined by its position from the right:
| 11112 | = 810 + 410 + 210 + 110 |
| = 1510 |
| 010111101011010100102 | = 26214410 + 6553610 + 3276810 + 1638410 + 819210 + 204810 + 51210 + 25610 + 6410 + 1610 + 210 |
| = 38792210 |
| 010111101011010100102 | = | 0101 | 1110 | 1011 | 0101 | 00102 |
| = | 5 | E | B | 5 | 216 | |
| = | 5EB5216 | |||||
Octal is also useful as a way for humans to deal with computer data (in blocks of 3 bits instead of 4); however, hexadecimal's big advantage over octal is that exactly 2 digits represent a byte (octet). This means that with hexadecimal, you can easily see from the value of a word what the value of the individual bytes will be; conversely, if you have the values of the bytes, you can easily assemble them to get the value of a word.
Let d be the decimal number to convert, and the series hihi-1...h2h1 be the hexadecimal digits representing the number.
1. H1 := d mod 16
2. D := (d-h1) / 16
3. If d==0 (return series hi)
else go to 1
"16" may be replaced with any other base that may be desired.
The following is a JavaScript implementation of the above algorithm for converting any number to a hexadecimal in String representation. Its purpose is to illustrate the above algorithm (maybe other uses that may be thought of). To work with data seriously however, it is much more advisable to work with bitwise operators.
function toHex(d) {
var r = d % 16;
if(d-r==0) {return toChar(r);}
else {return toHex( (d-r)/16 )+toChar(r);}
}
function toChar(n) {
var alpha = "0123456789ABCDEF";
return alpha.charAt(n);
}
In the TV show ReBoot there is a villainous character named Hexadecimal, who appears as a harlequin with constantly-changing masks, each with a different facial expression to represent differing emotional states.
In 1998, Subaru sold a special edition Impreza called the WRX-STi 22B. While some contend the name was derived from the use of a 2.2L motor ("22") and Bilstein brand ("B") suspension components, it has also been shown that "22B" is the hexadecimal equivalent of "555," where State Express 555 is the British American Tobacco brand that sponsored Subaru's early rally efforts.
Computer arithmetic | Positional numeral systems
نظام عد سداسي عشر | Hexadecimální číslo | Hexadecimale talsystem | Hexadezimalsystem | Δεκαεξαδικό σύστημα αρίθμησης | Sistema hexadecimal | Deksesuma sistemo | Zenbaki-sistema hamaseitar | Système hexadécimal | Código hexadecimal | 십육진법 | Heksadekadski broj | Sextándakerfið | Sistema numerico esadecimale | בסיס הקסדצימלי | Tizenhatos számrendszer | Hexadecimaal | 十六進記数法 | Sekstentallsystemet | Sekstentalssystemet | Szesnastkowy system liczbowy | Sistema hexadecimal | Шестнадцатеричная система счисления | Šestnástková sústava | Šestnajstiški številski sistem | Хексадецимални систем | Heksadesimaalijärjestelmä | Sedecimala talsystemet | เลขฐานสิบหก | Hệ thập lục phân | Heksadesimal | 十六进制
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Hexadecimal".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world