Python – hex()
Python hex() builtin function converts an integer to a lowercase hexadecimal string prefixed with “0x”
.
Syntax
The syntax of hex()
function is
hex(n)
where
n
is an integer.
hex() function returns a string value.
Examples
Convert integer to hexadecimal
In the following program, we take an integer value in n
, and convert this integer into hexadecimal representation.
Python Program
n = 2558
output = hex(n)
print(output)
Run Output
0x9fe
Summary
In this tutorial of Python Examples, we learned the syntax of hex() builtin function, and how to use this function to convert given integer into hexadecimal representation, with examples.