Convert Hex to String in Python Last Updated : 15 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Hexadecimal (base-16) is a compact way of representing binary data using digits 0-9 and letters A-F. It's commonly used in encoding, networking, cryptography and low-level programming. In Python, converting hex to string is straightforward and useful for processing encoded data.Using List ComprehensionThis method splits the hex string into pairs of characters, converts each to an integer, then to a character (using ASCII values ) and then joins the result to form a string. Python hex_str = "5072616a6a77616c" res = ''.join([chr(int(hex_str[i:i+2], 16)) for i in range(0, len(hex_str), 2)]) print(res) print(type(res)) OutputPrajjwal <class 'str'> Explanation:The hex string is split into 2-character chunks.Each chunk is converted from base-16 to an integer using int(..., 16).chr() converts each integer to its corresponding character.join() merges all characters into a single string.Other Methods to Convert Hex to String:Using List ComprehensionUsing codecs.decode()Using bytes.fromhex()Let's discuss how to use these methods with examples:Using codecs.decode()The codecs module can directly decode a hex string into bytes, which can then be converted to a string. Python import codecs hex_str = "507974686f6e" res = codecs.decode(hex_str, 'hex').decode('utf-8') print(res) print(type(res)) OutputPython <class 'str'> Explanation:codecs.decode(hex_str, 'hex') converts the hex string into bytes..decode('utf-8') converts those bytes into a readable string.Using bytes.fromhex()This built-in method converts a hex string into bytes. Use .decode() to convert it to a UTF-8 string. Python hex_str = "4765656b73666f724765656b73" res = bytes.fromhex(hex_str).decode('utf-8') print(res) print(type(res)) OutputGeeksforGeeks <class 'str'> Explanation:bytes.fromhex() converts the hex string into a bytes object..decode('utf-8') turns those bytes into a standard string.Also reads: Python, hexadecimal, list comprehension, codecs.decode(), bytes.fromhex(). Comment More infoAdvertise with us Next Article Convert Hex to String in Python V venkateshk1220 Follow Improve Article Tags : Python Geeks Premier League Geeks Premier League 2023 Practice Tags : python Similar Reads Convert Hex String to Bytes in Python Converting a hexadecimal string to bytes in Python involves interpreting each pair of hexadecimal characters as a byte. For example, the hex string 0xABCD would be represented as two bytes: 0xAB and 0xCD. Letâs explore a few techniques to convert a hex string to bytes.Using bytes.fromhex() bytes.fro 2 min read Convert hex string to float in Python Converting a hex string to a float in Python involves a few steps since Python does not have a direct method to convert a hexadecimal string representing a float directly to a float. Typically, a hexadecimal string is first converted to its binary representation, and then this binary representation 3 min read Convert String to Int in Python In Python, converting a string to an integer is important for performing mathematical operations, processing user input and efficiently handling data. This article will explore different ways to perform this conversion, including error handling and other method to validate input string during conver 3 min read Convert Hex String To Integer in Python Hexadecimal representation is commonly used in computer science and programming, especially when dealing with low-level operations or data encoding. In Python, converting a hex string to an integer is a frequent operation, and developers have multiple approaches at their disposal to achieve this tas 2 min read Convert Decimal to String in Python Python defines type conversion functions to directly convert one data type to another. This article is aimed at providing the information about converting decimal to string. Converting Decimal to String str() method can be used to convert decimal to string in Python. Syntax: str(object, encoding=âut 1 min read Like