Python - Ways to convert hex into binary Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report We are given a hexadecimal number we need to convert it to binary. For example a = "1A3" we need to convert it to binary so that resultant output should be 110100011.Using bin() and int()We can convert hexadecimal to binary by first converting it to an integer using int() and then using the bin() function. Python a = "1A3" # Convert hexadecimal to an integer d = int(a, 16) # Convert integer to binary using bin() b = bin(d)[2:] # Remove the "0b" prefix print("Binary:", b) OutputBinary: 110100011 Explanation:int(a, 16) converts hexadecimal string "1A3" to its equivalent integer value.bin(d)[2:] converts integer to binary and removes "0b" prefix to get final binary representation.Using format()format() function allows us to convert a number to binary without the "0b" prefix. Python a = "1A3" # Convert to binary using format() b = format(int(a, 16), 'b') print("Binary:", b) OutputBinary: 110100011 Explanation:int(a, 16) converts the hexadecimal string "1A3" to its corresponding integer value.format(int(a, 16), 'b') converts integer to a binary string without "0b" prefix providing binary representation directly Comment More infoAdvertise with us Next Article Python | Decimal to binary list conversion G garg_ak0109 Follow Improve Article Tags : Python Python Programs Practice Tags : python Similar Reads Python Program to Convert Binary to Hexadecimal Given a binary number, the task is to write a Python program to convert the given binary number into an equivalent hexadecimal number. i.e convert the number with base value 2 to base value 16. In hexadecimal representation we 16 values to represent a number. Numbers 0-9 are expressed by digits 0-9 4 min read How to Convert Binary Data to Float in Python? We are given binary data and we need to convert these binary data into float using Python and print the result. In this article, we will see how to convert binary data to float in Python. Example: Input: b'\x40\x49\x0f\xdb' <class 'bytes'>Output: 3.1415927410125732 <class 'float'>Explana 2 min read Python | Decimal to binary list conversion The conversion of a binary list to a decimal number has been dealt in a previous article. This article aims at presenting certain shorthand to do the opposite, i.e binary to decimal conversion. Let's discuss certain ways in which this can be done. Method #1 : Using list comprehension + format() In t 6 min read Python | Decimal to binary list conversion The conversion of a binary list to a decimal number has been dealt in a previous article. This article aims at presenting certain shorthand to do the opposite, i.e binary to decimal conversion. Let's discuss certain ways in which this can be done. Method #1 : Using list comprehension + format() In t 6 min read Python - Binary list to integer A binary list represents binary digits (0s and 1s) as individual elements of a list. This article will explore various methods to convert a binary list into an integer.Using int() with String ConversionThis is the most efficient method. By joining the binary list into a string and using the built-in 3 min read Python - Binary list to integer A binary list represents binary digits (0s and 1s) as individual elements of a list. This article will explore various methods to convert a binary list into an integer.Using int() with String ConversionThis is the most efficient method. By joining the binary list into a string and using the built-in 3 min read Like