Answers for "how to get binary number in python"

4

python int 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'
Posted by: Guest on May-13-2021
0

how to return number in binary python

pythonCopytemp = format(10, "b")

print(temp)
Posted by: Guest on September-27-2021

Code answers related to "how to get binary number in python"

Python Answers by Framework

Browse Popular Code Answers by Language