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
Tutorial
Bytes Objects: Handling Binary Data in Python
In this tutorial, you'll learn about Python's bytes objects, which help you process low-level binary data. You'll explore how to create and manipulate byte sequences in Python and how to convert between bytes and strings. Additionally, you'll practice this knowledge by coding a few fun examples.
For additional information on related topics, take a look at the following resources:
- How to Convert a Python String to int (Tutorial)
- Binary, Bytes, and Bitwise Operators in Python (Course)
- Bitwise Operators in Python (Tutorial)
- Python's Bytearray: A Mutable Sequence of Bytes (Tutorial)
- How to Convert Bytes to Strings in Python (Tutorial)
- Python Bytes (Quiz)
- Convert a Python String to int (Course)
- Bitwise Operators in Python (Quiz)
- Python's Bytearray (Quiz)
- How to Convert Bytes to Strings in Python (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Oct. 24, 2026