Is there an easy way to turn integers into binary numbers in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Is there an easy way to turn integers into binary numbers in Python?

in Ruby, you can do: x.to_s(2) Is there something similar in Python? If yes, please tell me. If no, tell me a short dec to bin converter code please

3rd Apr 2017, 8:39 PM
Supersebi3
Supersebi3 - avatar
2 Answers
+ 3
https://docs.python.org/3/library/functions.html#bin bin(x) "Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer."
3rd Apr 2017, 8:52 PM
Daniel Thomalla
Daniel Thomalla - avatar
+ 5
@Daniel Thomalla THANKS!
3rd Apr 2017, 8:53 PM
Supersebi3
Supersebi3 - avatar