Convert Hex to String in Python Last Updated : 15 Apr, 2025 Comments Improve Suggest changes 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 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 Convert String to Float in Python The goal of converting a string to a float in Python is to ensure that numeric text, such as "33.28", can be used in mathematical operations. For example, if a variable contains the value "33.28", we may want to convert it to a float to perform operations like addition or division. Let's explore dif 2 min read Convert Set to String in Python Converting a set to a string in Python means changing a group of unique items into a text format that can be easily read and used. Since sets do not have a fixed order, the output may look different each time. For example, a set {1, 2, 3} can be turned into the string "{1, 2, 3}" or into "{3, 1, 2}" 2 min read Convert String to Set in Python There are multiple ways of converting a String to a Set in python, here are some of the methods.Using set()The easiest way of converting a string to a set is by using the set() function.Example 1 : Pythons = "Geeks" print(type(s)) print(s) # Convert String to Set set_s = set(s) print(type(set_s)) pr 1 min read Convert String to Long in Python Python defines type conversion functions to directly convert one data type to another. This article is aimed at providing information about converting a string to long. Converting String to long A long is an integer type value that has unlimited length. By converting a string into long we are transl 1 min read Convert Hex To String Without 0X in Python Hexadecimal representation is a common format for expressing binary data in a human-readable form. In Python, converting hexadecimal values to strings is a frequent task, and developers often seek efficient and clean approaches. In this article, we'll explore three different methods to convert hex t 2 min read Like