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
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
- Memory addresses and pointers in debuggers
- Color specification in web design
- Byte dumps of files and network packets
- Fixed-width identifiers such as hashes and UUIDs
print(0x2F) # 47
print(hex(255)) # '0xff'
print(f'{182:02X}') # 'B6'