hexadecimal
Hexadecimal, or hex, is a base-16 positional number system that represents values with sixteen distinct symbols: the digits 0 through 9 followed by the letters A through F, which stand for the decimal values 10 through 15.
Each hexadecimal digit maps to exactly four binary bits, so a single byte always fits in two hex digits. That clean, lossless correspondence with binary makes hexadecimal a compact and readable shorthand for the raw bit patterns a computer stores, far shorter than the equivalent binary and aligned to byte boundaries in a way that decimal is not.
The interactive explorer below maps a hexadecimal value to its individual four-bit groups, updating the binary, decimal, and Python conversions together as the value changes.
Because its symbols overlap with ordinary decimal digits, a written hexadecimal value usually carries a marker that signals its base. Common conventions include the following:
0xprefix, used for integer literals in many languages, including Python, as in0xFFfor decimal 255.#prefix, used for RGB color codes in web design, where#FF8800mixes red, green, and blue channels.- Grouped pairs, used for byte-oriented data such as memory addresses, MAC addresses, and the output of a hex dump.
In Python, the hex() function turns an int into its hexadecimal string form, while an 0x literal or a base argument to int() converts a hex value back to a number.
Related Resources
Course
Binary, Bytes, and Bitwise Operators in Python
In this course, you'll learn how to use Python's bitwise operators to manipulate individual bits of data at the most granular level. With the help of hands-on examples, you'll see how you can apply bitmasks and overload bitwise operators to control binary data in your code.
For additional information on related topics, take a look at the following resources:
- Bitwise Operators in Python (Tutorial)
- Bytes Objects: Handling Binary Data in Python (Tutorial)
- Python's Bytearray: A Mutable Sequence of Bytes (Tutorial)
- How to Convert Bytes to Strings in Python (Tutorial)
- Bitwise Operators in Python (Quiz)
- Python Bytes (Quiz)
- Python's Bytearray (Quiz)
- How to Convert Bytes to Strings in Python (Quiz)
By Martin Breuss • Updated July 18, 2026