Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # paulogp
- def dec2bin(n):
- ''' converte um numero decimal em binario. retorna string '''
- bStr = ''
- if n < 0:
- raise ValueError, "deve inserir um valor positivo!"
- if n == 0:
- return '0'
- while n > 0:
- bStr = str(n % 2) + bStr
- n = n >> 1
- return bStr
- # exemplo
- print(dec2bin(24))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement