Skip to content

Instantly share code, notes, and snippets.

@190n
Created February 4, 2020 04:07
Show Gist options
  • Save 190n/4979422017ec9063baac32123fcf8788 to your computer and use it in GitHub Desktop.
Save 190n/4979422017ec9063baac32123fcf8788 to your computer and use it in GitHub Desktop.
Binary to decimal conversion with Python
def binary_to_decimal_iterative(binary):
total = 0
for i in range(len(binary)):
if binary[i] == '1':
pass
return total
def binary_to_decimal_recursive(binary):
if len(binary) == 1:
return int(binary)
else:
rest = binary_to_decimal_recursive(binary[1:])
if binary[0] == '1':
pass
else:
return rest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment