Skip to content

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.

Interactive diagram — enable JavaScript to view.

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:

  • 0x prefix, used for integer literals in many languages, including Python, as in 0xFF for decimal 255.
  • # prefix, used for RGB color codes in web design, where #FF8800 mixes 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.

Bytes Objects: Handling Binary Data in Python

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.

intermediate python

For additional information on related topics, take a look at the following resources:

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