Quantcast
Channel: Convert int to binary string in Python - Stack Overflow
Viewing all articles
Browse latest Browse all 74

Answer by quents for Python int to binary string?

$
0
0

Here is the code I've just implemented. This is not a method but you can use it as a ready-to-use function!

def inttobinary(number):  if number == 0:    return str(0)  result =""  while (number != 0):      remainder = number%2      number = number/2      result += str(remainder)  return result[::-1] # to invert the string

Viewing all articles
Browse latest Browse all 74

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>