EMZETT.
Login

Hex Codes

In short: Values in hexadecimal notation (base 16) — widely used in IT to represent bytes compactly, for example for colours (#FF0000 for red).

In more detail: A byte (8 bits, values 0–255) can be represented exactly with two hex digits (00–FF), which makes hexadecimal considerably more compact than binary notation and easier for humans to read than pure binary numbers. Used, among other things, for memory addresses, MAC addresses and colour values.

In Depth

Why base 16 specifically?

Hexadecimal uses 16 digits (0-9 and A-F for the values 10-15) instead of the ten digits of the decimal system. The practical advantage over binary: each individual hex digit corresponds exactly to four bits (a “nibble”), so bytes can be converted to hex losslessly and compactly — 11111111 (binary) becomes FF (hex), considerably more readable than a long chain of zeros and ones. This exact 4-bit correspondence is the actual reason hex became established rather than, say, base 12 or 20: with base 16, every hex digit can be broken down into its 4 bits independently of its neighbours, while with other bases the conversion would be considerably more awkward.

Decimal:     255
Binary:      11111111
Hexadecimal: FF

Decimal:     4096
Binary:      0001 0000 0000 0000
Hexadecimal: 1000

Typical uses

  • Colour values in web/design: #FF0000 = red (FF for the red channel, 00 for green and blue), #1a1a2e = a dark blue-violet. Each of the three channels (RGB) gets exactly one byte (two hex digits, values 00–FF), making 6 hex digits per colour in total — with an optional fourth alpha channel (#FF0000FF) for transparency.
  • MAC addresses: 00:1A:2B:3C:4D:5E — six byte pairs, separated by colons or hyphens, where the first half identifies the manufacturer (OUI, “Organizationally Unique Identifier”).
  • Memory addresses when debugging: debuggers and crash dumps almost always show memory addresses in hexadecimal (e.g. 0x7FFE12340000), since address widths (32-bit, 64-bit) translate cleanly into hex digits.
  • Hash output: Git commit hashes, SHA-256 checksums and most cryptographic hash functions are conventionally shown as a hex string, since raw binary data wouldn’t be directly readable/copyable.
  • Unicode code points: characters like emoji are often written as U+1F600 — that’s also a hex number.

Prefixes and notations

Depending on the programming language/context, there are different conventions for explicitly marking a number as hex: 0x as a prefix is standard in most C-like languages (C, C++, Java, JavaScript, Python) (0xFF), CSS/web instead uses # (#FF0000), and some assembler dialects append an h (FFh). Without one of these markers, FF wouldn’t be distinguishable from any arbitrary text string — the context (e.g. a variable explicitly parsed as a hex number) makes the difference.

Hex editors

A hex editor shows the raw byte content of any file directly as hex values (instead of an interpreted representation, as a normal text program would give) — useful for debugging file formats, analysing potentially malicious files, or understanding binary formats for which there’s no suitable application. Each byte typically appears both as a two-digit hex value and, if printable, as the corresponding ASCII character next to it.

See also: Bytes, MAC Addresses, CSS