how to set binary to 8 bit in python code example
Example 1: binary number in python 32 bit
>>> '{:032b}'.format(100)
'00000000000000000000000001100100'
>>> '{:032b}'.format(8589934591)
'111111111111111111111111111111111'
>>> '{:032b}'.format(8589934591 + 1)
'1000000000000000000000000000000000'
Example 2: how to convert from binary to base 10 in python
def getBaseTen(binaryVal):
count = 0
binaryVal = binaryVal[::-1]
for i in range(0, len(binaryVal)):
if(binaryVal[i] == "1"):
count += 2**i
return count