Number to binary string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thierry Conter
    New Member
    • May 2011
    • 4

    Number to binary string

    Hi everyone,

    i would like to know if there is in python a way of converting a number into its 8bit long binary representation? in fact i know that the function bin() does that but for small numbers not in 8bit representation.
    ex:
    bin(56) returns 0b111000 (which is a 6bit representation)
    i would like to have this:
    bin(56) -> 0b00111000 (8bit representation)
    or bin(2) -> 0b00000010
    is that possible in python or do i have to write my own function for this?

    Thanks
    Thierry
Working...