← Go Back

How to Convert Decimal to Hexadecimal (And Vice Versa)

The hex() built-in function takes an integer and returns its hexadecimal representation as a string:

>>> hex(255)

To get the decimal number back, use the int() function:

# The '0x' prefix is optional.
>>> int("0xff", 16)

integers hexadecimal

🐍 You might also find interesting: