Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv
- from random import randint
- def b2int(array, i=0, dec=0):
- """ Convert a list to integer numbers """
- for string in array:
- i, dec = 0, 0
- while (i < len(string)):
- dec += int(string[::-1][i]) * (2 ** i)
- i += 1
- yield dec
- def int2b(array):
- """ Convert a list to binary numbers """
- for n in array:
- binary = ''
- while n > 0:
- if n % 2 == 0:
- binary = '0' + binary
- else:
- binary = '1' + binary
- n /= 2
- yield binary
- print(list(int2b([10, 11, 12, 13, 14, 15, 16])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement