$devtoolkit.sh/glossary/what-is-hex

What is Hexadecimal? — The Base-16 Number System

Definition

Hexadecimal, or hex, is a base-16 numeral system that uses sixteen distinct symbols: the digits 0–9 and the letters A–F (or a–f). Hex is widely used in computing because it provides a compact, human-readable representation of binary data. Each hex digit corresponds exactly to 4 binary bits, so one byte (8 bits) is always representable as exactly two hex digits, making hex a natural fit for expressing byte values, memory addresses, and color codes.

How It Works

Each position in a hex number represents a power of 16. The rightmost digit is 16^0 (ones), the next is 16^1 (sixteens), and so on. To convert hex to decimal, multiply each digit by its positional power of 16 and sum the results. For example, 0xFF = 15×16^1 + 15×16^0 = 240 + 15 = 255. To convert binary to hex, group the bits in sets of 4 from right to left and replace each group with its hex equivalent. For example, 11111111 binary = 1111 1111 = F F = 0xFF.

Common Use Cases

  • Defining colors in CSS (#FF5733 is red=255, green=87, blue=51)
  • Representing memory addresses in debugging and low-level programming
  • Displaying byte values in hex editors and binary file inspection tools
  • Encoding cryptographic hashes like MD5 and SHA-256 as readable strings
  • Expressing bitmasks and flags in system programming

Example

Decimal 255 = Hex FF = Binary 11111111
Decimal 16  = Hex 10 = Binary 00010000
Decimal 255 = Hex FF

CSS color: #1A2B3C
R: 0x1A = 26
G: 0x2B = 43
B: 0x3C = 60

Related Tools

FAQ

Why do programmers prefer hex over decimal for byte values?
A single byte has 256 possible values (0–255). In hex, this range is 0x00–0xFF — always exactly two digits. In decimal, the range 0–255 uses 1–3 digits. Hex keeps byte values a consistent width, making them easier to read side by side.
What does the 0x prefix mean?
0x is a conventional prefix used in C, C++, Python, JavaScript, and many other languages to mark a numeric literal as hexadecimal. For example, 0xFF means the hex value FF (decimal 255), not the decimal number with digits 0, x, F, F.
How do hex color codes work?
A CSS hex color like #FF8800 encodes three bytes: one each for the red, green, and blue channel. FF is 255 (maximum red), 88 is 136 (medium green), 00 is 0 (no blue). A 3-digit shorthand like #F80 expands each digit by doubling it: #FF8800.

Related Terms

/glossary/what-is-hexv1.0.0