Computing Library › Number Systems & Information
Number Systems & Information

Hexadecimal Number System

Hexadecimal is base 16; each digit encodes exactly four bits, making it the standard shorthand for binary.

Base sixteen

Hexadecimal uses sixteen digits: 0–9 followed by A–F for the values ten through fifteen. Because 16 = 2⁴, one hex digit represents exactly four bits, and two hex digits represent one byte.

Reading a value

Kronos motion — number counters

The string 0x2F means 2×16 + 15 = 47 in decimal. The prefix 0x marks a hexadecimal literal in most programming languages.

Why it dominates

A byte is eight bits, which is two hex digits, so any byte-oriented data — memory addresses, color codes, hashes, machine code — reads cleanly in hex. The color #FF8000, for example, packs three bytes of red, green, and blue.

Binary conversion

Group bits in fours from the right and translate each group. The binary 10110110 splits into 1011 and 0110, giving 0xB6. The mapping is direct and needs no arithmetic.

Common uses

python
print(0x2F)        # 47
print(hex(255))    # '0xff'
print(f'{182:02X}')  # 'B6'