Existe-t-il des méthodes Python classiques pour convertir un Integer (ou Long) en chaîne binaire en Python ?
Il existe une myriade de fonctions dec2bin() sur Google... Mais j'espérais pouvoir utiliser une fonction / bibliothèque intégrée.
La méthode de formatage des chaînes de Python peut prendre en compte une spécification de format.
>>> "{0:b}".format(37)
'100101'
[Docs sur les spécifications de format pour Python 2][1]
[Format de la documentation pour Python 3][2]
[1] : https://docs.python.org/2/library/string.html#formatspec [2] : https://docs.python.org/3/library/string.html#formatspec
Si vous recherchez [bin()
][1] comme équivalent à hex()
, il a été ajouté dans python 2.6.
Exemple :
>>> bin(10)
'0b1010'