Hexadecimal Explained

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.

Representation

Written representation

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.

00000000 57 69 6b 69 70 65 64 69 61 2c 20 74 68 65 20 66 00000010 72 65 65 20 65 6e 63 79 63 6c 6f 70 65 64 69 61 00000020 20 74 68 61 74 20 61 6e 79 6f 6e 65 20 63 61 6e 00000030 20 65 64 69 74 0a

Distinguishing from decimal

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:

Notes and References

  1. News: The hexadecimal system . 2022-08-26 . Ionos Digital Guide . en . 2022-08-26 . https://web.archive.org/web/20220826084201/https://www.ionos.co.uk/digitalguide/server/know-how/hexadecimal-system/ . live .
  2. Book: Knuth, Donald Ervin . The TeXbook . 1986 . Duane Bibby . 0-201-13447-0 . Reading, Mass. . 12973034 . 2022-03-15 . 2022-01-16 . https://web.archive.org/web/20220116012119/http://www.worldcat.org/oclc/12973034 . live .
  3. The string "\x1B[0m\x1B[25;1H" specifies the character sequence