You are looking for the chr function.

You seem to be mixing decimal representations of integers and hex representations of integers, so it's not entirely clear what you need. Based on the description you gave, I think one of these snippets shows what you want.

>>> chr(0x65) == '\x65'
True


>>> hex(65)
'0x41'
>>> chr(65) == '\x41'
True

Note that this is quite different from a string containing an integer as hex. If that is what you want, use the hex builtin.

Answer from Mike Graham on Stack Overflow
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-a-decimal-number-to-hexadecimal-in-python
How to convert a decimal number to hexadecimal in Python
Line 4โ€“5: The function starts with a special case: if the input decimal_num is 0, it directly returns โ€œ0โ€ since the hexadecimal representation of 0 is โ€œ0โ€. Line 8โ€“13: Inside the while loop, the decimal number is continuously divided by 16, and the remainder is used to index into the hex_characters string to get the corresponding hexadecimal digit.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ built-in โ€บ hex
Python hex() - Convert Integer to Hexadecimal | Vultr Docs
November 25, 2024 - The hex() function in Python is a built-in method used to convert an integer into its corresponding hexadecimal string. This function is particularly useful in fields like cryptography, computer science education, or any scenario where hexadecimal ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ hex
Python hex()
The hex() function converts an integer number to the corresponding hexadecimal string.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-hex
Python hex() | DigitalOcean
August 3, 2022 - Python hex() function is used to convert an integer to a lowercase hexadecimal string prefixed with โ€œ0xโ€. We can also pass an object to hex() function, in that case the object must have __index__() function defined that returns integer. The input integer argument can be in any base such ...
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ how-to-convert-an-int-to-a-hex-string-bf910545b3e8
How to Convert an Int to a Hex String? | by whyamit404 | Medium
February 8, 2025 - Simply put, the hex() function helps you take a regular integer (like 10 or 255) and transform it into its hexadecimal string counterpart. For instance, the number 255 becomes '0xff', where the 0x at the start indicates itโ€™s a hexadecimal number.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-hex-function
hex() function in Python - GeeksforGeeks
July 11, 2025 - hex() function in Python is used to convert an integer to its hexadecimal equivalent. It takes an integer as input and returns a string representing the number in hexadecimal format, starting with "0x" to indicate that it's in base-16.
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ built-in-function โ€บ hex.php
Python hex() function - w3resource
September 20, 2024 - Python hex() function: The hex() function converts an integer number to a lowercase hexadecimal string prefixed with 0x.
Find elsewhere
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ print int as hex in python
Print int as hex in Python [3 ways] - Java2Blog
November 27, 2023 - The "x" in {number:x} specifies hexadecimal formatting, producing "ff". ... F-strings are efficient and highly readable, often offering better performance than traditional formatting methods. Below is a Python script that uses the timeit module to compare the performance of different methods for converting an integer to a hexadecimal string, both with and without the 0x prefix.
๐ŸŒ
Appdividend
appdividend.com โ€บ python-hex
Python hex(): Converting an Integer to Hex
September 4, 2025 - Python hex() function converts an integer number into a lowercase hexadecimal string prefixed with '0x' (or '-0x' for negative values).
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ python โ€“ convert integer to hexadecimal
Python - Convert Integer to Hexadecimal - Data Science Parichay
March 13, 2022 - You can use the Python built-in hex() function to convert an integer to its hexadecimal form in Python. Pass the integer as an argument to the function.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_hex.asp
Python hex() Function
Python Bootcamp Python Certificate Python Training ... The hex() function converts the specified number into a hexadecimal value. The returned string always starts with the prefix 0x.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Convert Binary, Octal, Decimal, and Hexadecimal in Python | note.nkmk.me
May 19, 2023 - For example, use 0b1111 (= 0xf) for 4-bit, 0xff for 8-bit, and 0xffff for 16-bit representations. ... You can use the built-in function int() to convert a binary, octal, or hexadecimal string into a number.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-hex-string-to-integer-in-python
Convert Hex String To Integer in Python - GeeksforGeeks
July 23, 2025 - The resulting `decimal_integer` is 64034. ... In this example, the hexadecimal string "0xfe00" is converted to an integer using the `literal_eval()` function from the `ast` module.
๐ŸŒ
Finxter
blog.finxter.com โ€บ python-integer-to-hex-the-ultimate-guide
Python Integer to Hex โ€” The Ultimate Guide โ€“ Be on the Right Side of Change
You can choose the method that best suits your needs and is compatible with your version of Python. Converting negative integers and zero to their corresponding hexadecimal representation in Python can be achieved using the hex() function, which produces a string output prefixed with '0x' for ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python integer to hex string (easy)
Python Integer to Hex String (Easy) - Be on the Right Side of Change
November 16, 2022 - The easiest way to convert a decimal integer number x to a hexadecimal string is to use the built-in Python function hex(x).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-convert-decimal-to-hexadecimal
Python Program to Convert Decimal to Hexadecimal - GeeksforGeeks
July 23, 2025 - hex() function is one of the built-in functions in Python3, which is used to convert an integer number into its corresponding hexadecimal form.
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ hex-builtin
Python hex Function - Complete Guide
This comprehensive guide explores Python's hex function, which converts integers to hexadecimal strings.
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ python โ€บ python-integer-to-hex-format
How to convert Integer to Hex Format in Python?
July 24, 2021 - format() function returns a string with the hex representation of given integer. ... In this example, we take an integer value and format it to Hex upper-case, using format() builtin function.