Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Are there any canned Python methods to convert an Integer (or Long) into a binary string in Python?

There is a myriad of dec2bin() functions out on Google... But I was hoping I could use a built-in function/library.

1 Answer

0 votes
by (106k points)

Python's string format method can take a format spec.

>>> "{0:b}".format(37) 

'100101'

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 15, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...