Tom Church
0
Q:

binary to decimal python

a = 5
#this prints the value of "a" in binary
print(bin(a))
9
int(binaryString, 2)
2
a = 10
#this will print a in binary
bnr = bin(a).replace('0b','')
x = bnr[::-1] #this reverses an array
while len(x) < 8:
    x += '0'
bnr = x[::-1]
print(bnr)
2
format(decimal ,"b")
0
DecimalToBinary(num):
        if num > 1:
            DecimalToBinary(num // 2)
            print num % 2
-2

Tags

New to Communities?

Join the community