Binary to denary · Binário para decimal
Binary to denary
Convert a binary number, written as a string, to denary (base 10).
Read the bits from left to right. Each new bit doubles the value so far and then adds itself: for "101" the value goes 1, then 1 * 2 + 0 = 2, then 2 * 2 + 1 = 5. int("1") turns the character into the number 1.
Binário para decimal
Converta um número binário, escrito como string, para decimal (base 10).
Leia os bits da esquerda para a direita. Cada novo bit dobra o valor atual e depois se soma: para "101", o valor vai de 1, depois 1 * 2 + 0 = 2, depois 2 * 2 + 1 = 5. int("1") converte o caractere no número 1.
Write to_denary(bits) that turns a string of 0s and 1s into its whole-number value, without using int(bits, 2). "1011" is 11. · Escreva to_denary(bits) que transforme uma string de 0s e 1s em seu valor numérico inteiro, sem usar int(bits, 2). "1011" é 11.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.