Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def toDecimal(binario,mostrar=False):
- soma,i = 0,0
- for x in str(binario):
- soma = 2*soma+int(x)
- if mostrar == True : print(x, '+ 2 ^', i, '=',soma)
- if soma ==0: soma = 1
- i+=1
- print(soma)
- toDecimal(1001,True) #Para usar, chame a função com o seu numero binario, True (se quiser que exiba os calculos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement