Integer to Binary String in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 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 R reshmah Follow 0 Improve R reshmah Follow 0 Improve Article Tags : Python Python Programs python-string python-basics Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like