Integer to Binary String in Python Last Updated : 25 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report We have an Integer and we need to convert the integer to binary string and print as a result. In this article, we will see how we can convert the integer into binary string using some generally used methods.Example: Input : 77Output : 0b1001101Explanation: Here, we have integer 77 which we converted into binary stringUsing bin()bin() function is the easiest way to convert an integer into a binary string. It returns the binary with a "0b" prefix to indicate it's a binary number. Python n = 77 b = bin(n) print(type(b),b) Output<class 'str'> 0b1001101 Using format()format() function lets you convert a number to binary without the "0b" prefix. It gives you more control over formatting. Python n = 81 b = format(n, 'b') print(type(b),b) Output<class 'str'> 1010001 Using Bitwise operationsThis method builds the binary string manually by dividing the number by 2 and collecting remainders. It's slower but helps you understand how binary conversion works. Python n = 42 orig = n b = '' while n > 0: b = str(n % 2) + b n //= 2 b = b if b else '0' print(type(b),b) Output<class 'str'> 101010 Explanation: We store the original number in orig, then use a loop to divide it by 2 and prepend each remainder (n % 2) to the string b. This builds the binary representation from right to left. If the number is 0, we set b to "0".Related articles:bin()format()Related ArticlesConvert Binary to IntegerString format() MethodPython Bitwise OperatorsPython Data Types Comment More infoAdvertise with us Next Article Python - Convert Binary tuple to Integer R reshmah Follow Improve Article Tags : Python Python Programs python-string python-basics Practice Tags : python Similar Reads 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 - Convert Binary tuple to Integer Given Binary Tuple representing binary representation of a number, convert to integer. Input : test_tup = (1, 1, 0) Output : 6 Explanation : 4 + 2 = 6. Input : test_tup = (1, 1, 1) Output : 7 Explanation : 4 + 2 + 1 = 7. Method #1 : Using join() + list comprehension + int() In this, we concatenate t 5 min read Python Program to Generate Random binary string Given a number n, the task is to generate a random binary string of length n.Examples: Input: 7 Output: Desired length of random binary string is: 1000001 Input: 5 Output: Desired length of random binary string is: 01001 Approach Initialize an empty string, say key Generate a randomly either "0" or 2 min read Convert Floating to Binary - Python The task of converting a floating-point number to its binary representation in Python involves representing the number in the IEEE 754 format, which consists of a sign bit, an exponent and a mantissa. For example, given the floating-point number 10.75, its IEEE 754 32-bit binary representation is "0 3 min read Python Check If String is Number In Python, there are different situations where we need to determine whether a given string is valid or not. Given a string, the task is to develop a Python program to check whether the string represents a valid number.Example: Using isdigit() MethodPython# Python code to check if string is numeric 6 min read Python Program to Subtract Two Binary Numbers We are given two binary numbers, num1 and num2 and we have to subtract these two binary numbers and return the result. In this article, we will see how we can subtract two binary numbers in Python.Examples:Input: a = "1110" , b = "0110"Output: "1000"Explanation: We can see that when "1110" is subtra 3 min read Like