且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将十进制数转换为6位二进制数

更新时间:2021-12-31 23:14:48

要么马特(Matt)在评论中说(bin(63)[2:].zfill(6)),要么使用

Either what Matt said in the comment (bin(63)[2:].zfill(6)), or use format strings in Python 2.6+:

'{0:06b}'.format(63)

您可以省略Python 2.7+中的第一个零,因为您可以隐式地对组进行编号.

You can omit the first zero in Python 2.7+ as you can implicitly number groups.