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

Answer by kcrisman for Convert int to binary string in Python

$
0
0

If you are willing to give up "pure" Python but gain a lot of firepower, there is Sage - example here:

sage: a = 15sage: a.binary()'1111'

You'll note that it returns as a string, so to use it as a number you'd want to do something like

sage: eval('0b'+b)15

Viewing all articles
Browse latest Browse all 74

Trending Articles



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