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.

Bitwise Operators in Python

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.

intermediate python

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


By Martin Breuss • Updated July 18, 2026