Convert an integer to binary without using the built-in bin function

后端 未结 15 1545
深忆病人
深忆病人 2020-12-07 01:14

This function receives as a parameter an integer and should return a list representing the same value expressed in binary as a list of bits, where the first element in the l

15条回答
  •  悲&欢浪女
    2020-12-07 01:33

    Convert integer to list of bits with a fixed length :

    [int(x) for x in list('{0:0{width}b}'.format(8, width=5))]
    

提交回复
热议问题