- You are here
- Everything Explained.Today
- A-Z Contents
- H
- HE
- HEX
- HEXA
- HEXAD
- Hexadecimal

In mathematics and computing, the **hexadecimal** (also **base 16** or **hex**) numeral system is a positional numeral system that represents numbers using a radix (base) of 16. Unlike the common way of representing numbers using 10 symbols, hexadecimal uses 16 distinct symbols, most often the symbols "0"–"9" to represent values 0 to 9, and "A"–"F" (or alternatively "a"–"f") to represent values 10 to 15.

Hexadecimal numerals are widely used by computer system designers and programmers because they provide a human-friendly representation of binary-coded values. Each hexadecimal digit represents four bits (binary digits), also known as a nibble (or nybble), which is 1/2 of a byte. For example, a single byte can have values ranging from 00000000 to 11111111 in binary form, which can be conveniently represented as 00 to FF 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, a number of notations are used to denote hexadecimal numbers, usually involving a prefix or suffix. The prefix `0x`

is used in C and related programming languages, which would denote this value as `0x{{hexadecimal|{{#invoke:random|number|65535|same=yes}}|no}}`

.

Hexadecimal is used in the transfer encoding **Base16**, in which each byte of the plaintext is broken into two 4-bit values and represented by two hexadecimal digits.

In almost all modern use, the letters A–F or a–f represent the values 10–15, while the numerals 0–9 are used to represent their usual 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 often used. Seven-segment displays use mixed-case AbCdEF to make digits that can be distinguished from each other.

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: 159_{10} is decimal 159; 159_{16} is hexadecimal 159, which is equal to 345_{10}. Some authors prefer a text subscript, such as 159_{decimal} and 159_{hex}, or 159_{d} and 159_{h}.

Donald Knuth introduced the use of a particular typeface to represent a particular radix in his book *The TeXbook*.^{[1]} 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:

- Unix (and related) shells, AT&T assembly language and likewise the C programming language (and its syntactic descendants such as C++, C#, Go, D, Java, JavaScript, Python and Windows PowerShell) use the prefix
`0x`

for numeric constants represented in hex:`0x5A3`

. 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.^{[2]}

- Donald E. Knuth.
*The TeXbook*(Computers and Typesetting, Volume A). Reading, Massachusetts: Addison–Wesley, 1984. . The source code of the book in TeX (and a required set of macros [ftp://tug.ctan.org/pub/tex-archive/systems/knuth/lib/manmac.tex CTAN.org]) is available online on CTAN. - The string
`"\x1B[0m\x1B[25;1H"`

specifies the character sequence