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

Answer by Chandler for Python int to binary string?

$
0
0

Somewhat similar solution

def to_bin(dec):    flag = True    bin_str = ''    while flag:        remainder = dec % 2        quotient = dec / 2        if quotient == 0:            flag = False        bin_str += str(remainder)        dec = quotient    bin_str = bin_str[::-1] # reverse the string    return bin_str 

Viewing all articles
Browse latest Browse all 74

Trending Articles



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