Hexadecimal
In mathematics, hexadecimal (often abbreviated hex) is a base 16 numeral system, usually written using the symbols 0-9 and A-F or a-f. It is a useful system in computers because there is an easy mapping from four bits to a single hex digit. Thus one can represent every byte as two consecutive hexadecimal digits. Compare the binary, hex and decimal representations in the chart on the right side of the page.
bin hex dec 0000 = 0 = 0 0001 = 1 = 1 0010 = 2 = 2 0011 = 3 = 3 0100 = 4 = 4 0101 = 5 = 5 0110 = 6 = 6 0111 = 7 = 7 1000 = 8 = 8 1001 = 9 = 9 1010 = A (~) = 10 1011 = B (!) = 11 1100 = C (@) = 12 1101 = D (#) = 13 1110 = E ($) = 14 1111 = F (%) = 15 |
There are many ways to denote hexadecimal numerals, used in different programming languages:
- Ada and VHDL enclose hexadecimal numerals in based "numeric quotes", e.g. "16#5A3#". (Note: Ada accepts this notation for all bases from 2 through 16 and for both integer and real types.)
- C and languages with a similar syntax (such as Java) prefix hexadecimal numerals with '0x', e.g. "0x5A3". The leading '0' is used so that the parser can simply recognise a number, and the 'x' stands for hexadecimal (c.f. O for Octal).
- in HTML, hexadecimal references also use the x: ֣ should give the same as ֣ With your browser ֣ and ֣ respectively (Hebrew accent munah).
- Pascal and some Assemblers indicate hex by an appended 'h' (if the numeral starts with a letter, then also with a preceding 0), e.g., "0A3Ch", "5A3h".
- Other assemblers (AT&T;, Motorola) and some versions of BASIC use a prefixed '$', e.g. "$5A3".
- Some versions of BASIC prefix hexadecimal numerals with "&h", e.g. "&h5A3".
- When talking about numeral systems other than base-10, or numerals in multiple bases, mathematicians write the base in subscript after the number, e.g. "5A316" or "5A3SIXTEEN".
The word "hexadecimal" is strange in that hexa is derived from the Greek έξι (hexi) for "six" and decimal is derived from the Latin for "ten". An older term was the pure Latin "sexidecimal", but that was changed because some people thought it too risque, and it also had an alternative meaning of "base 60".
A common use of hexadecimal numerals is found in web programming. The languages HTML and CSS use hexadecimal notation to specify colors on web pages; there is just the # symbol, not a separate symbol for "hexadecimal". 24-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. E.g., a shade of red that is 238,9,63 in decimal is coded as #EE093F. See Web colors.
In URLs special characters can be coded hexadecimally in ASCII with for each byte a percent sign (%) in front, e.g. http://en.wikipedia.org/wiki/Main%20Page
| Table of contents |
|
2 See also 3 External link |
Fractions
The hexadecimal system is quite good for forming fractions:
| 1/2 | = | 0.8 |
| 1/3 | = | 0.5555 recurring |
| 1/4 | = | 0.4 |
| 1/5 | = | 0.3333 recurring |
| 1/6 | = | 0.2AAAA recurring |
| 1/8 | = | 0.2 |
| 1/A | = | 0.19999 recurring |
| 1/C | = | 0.15555 recurring |
| 1/F | = | 0.1111 recurring |
Because the base is a square, hexadecimal fractions have an odd period much more often than decimal ones. Repeating decimals occur when the denominator has a prime factor not found in the base. In the case of hexadecimal numbers, this applies if and only if the denominator is not a power of two.
See also
External link