Skip to content

Instantly share code, notes, and snippets.

@vilaballack
Forked from fmasanori/dec2bin.py
Created May 20, 2022 00:05
Show Gist options
  • Save vilaballack/cd48c620cd1aafe6d93557ac149bf5a7 to your computer and use it in GitHub Desktop.
Save vilaballack/cd48c620cd1aafe6d93557ac149bf5a7 to your computer and use it in GitHub Desktop.
Decimal para binário em Python 3
def dec2bin(n):
b = ''
while n != 0:
b = b + str(n % 2)
n = int(n / 2)
return b[::-1]
def d2b(n):
if n == 0:
return ''
else:
return d2b(n//2) + str(n%2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment