from binary to decimal python code example
Example 1: convert hex to decimal python
myDecimalInteger = int("A278832", 16)
Example 2: binary to decimal in python
int(binaryString, 2)
Example 3: py convert binary to int
>>> bin(3)
'0b11'
>>> int(0b11)
3
Example 4: 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
Example 5: how to get the binary value in python
bin(19)
def binary(num):
array = []
while(num > 0):
sol1 = num / 2
check = sol1 - int(sol1)
if(check > 0):
array.append("1")
num = sol1 - 0.5
else:
array.append("0")
num = sol1
while(len(array) < 4):
array.append("0")
array = array[::-1]
string = ''.join(array)
return string