Convert binary string to binary literal

前端 未结 2 558
后悔当初
后悔当初 2020-12-20 13:40

I\'m using Python 3.2.2.

I\'m looking for a function that converts a binary string, e.g. \'0b1010\' or \'1010\', into a binary literal, e.g. 0b1010 (not a string or

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 14:05

    The string is a literal.

    3>> bin(int('0b1010', 2))
    '0b1010'
    3>> bin(int('1010', 2))
    '0b1010'
    3>> 0b1010
    10
    3>> int('0b1010', 2)
    10
    

提交回复
热议问题