In mathematics and computing, the hexadecimal (also base-16 or simply hex) numeral system is a positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbols, hexadecimal uses sixteen distinct symbols, most often the symbols "0"–"9" to represent values 0 to 9 and "A"–"F" (or "a"–"f") to represent values from ten to fifteen.
Software developers and system designers widely use hexadecimal numbers because they provide a convenient representation of binary-coded values. Each hexadecimal digit represents four bits (binary digits), also known as a nibble (or nybble).[1] For example, an 8-bit byte can have values ranging from to (0 to 255 decimal) in binary form, which can be written as to in hexadecimal.
In mathematics, a subscript is typically used to specify the base. For example, the decimal value would be expressed in hexadecimal as . In programming, several notations denote hexadecimal numbers, usually involving a prefix. The prefix 0x
is used in C, which would denote this value as 0x{{hexadecimal|{{#invoke:random|number|65535|same=yes}}|no}}
.
Hexadecimal is used in the transfer encoding Base 16, in which each byte of the plain text is broken into two 4-bit values and represented by two hexadecimal digits.
In most current use cases, the letters A–F or a–f represent the values 10–15, while the numerals 0–9 are used to represent their decimal values.
There is no universal convention to use lowercase or uppercase, so each is prevalent or preferred in particular environments by community standards or convention; even mixed case is used. Some Seven-segment displays use mixed-case 'A b C d E F' to distinguish the digits A–F from one another and from 0–9.
There is some standardization of using spaces (rather than commas or another punctuation mark) to separate hex values in a long list. For instance, in the following hex dump, each 8-bit byte is a 2-digit hex number, with spaces between them, while the 32-bit offset at the start is an 8-digit hex number.
In contexts where the base is not clear, hexadecimal numbers can be ambiguous and confused with numbers expressed in other bases. There are several conventions for expressing values unambiguously. A numerical subscript (itself written in decimal) can give the base explicitly: 15910 is decimal 159; 15916 is hexadecimal 159, which equals 34510. Some authors prefer a text subscript, such as 159decimal and 159hex, or 159d and 159h.
Donald Knuth introduced the use of a particular typeface to represent a particular radix in his book The TeXbook.[2] Hexadecimal representations are written there in a typewriter typeface:,
In linear text systems, such as those used in most computer programming environments, a variety of methods have arisen:
0x
for numeric constants represented in hex: 0x5A3
, 0xC1F27ED
. Character and string constants may express character codes in hexadecimal with the prefix \x
followed by two hex digits: '\x1B'
represents the Esc control character; "\x1B[0m\x1B[25;1H"
is a string containing 11 characters with two embedded Esc characters.[3]"\x1B[0m\x1B[25;1H"
specifies the character sequence