Konwertuj liczbę całkowitą na binarny Python
integer = 6
'{0:08b}'.format(integer)
# '00000110'
Anxious Alligator
integer = 6
'{0:08b}'.format(integer)
# '00000110'
# The int is 37
print("{0:b}".format(37))
# Output - '100101'
integer = 7
bit_count = 5
print(f'{integer:0{bit_count}b}') # 0 filled
format(6, "08b")
binary = bin(7)
print(binary)
print('{0:b}'.format(3)) # '11'
print('{0:8b}'.format(3)) # ' 11'
print('{0:08b}'.format(3)) # '00000011'
def int2bin(integer, digits):
if integer >= 0:
return bin(integer)[2:].zfill(digits)
else:
return bin(2**digits + integer)[2:]
print(int2bin(3, 6)) # '000011'