Skip to content

Instantly share code, notes, and snippets.

@hergerr
Created May 5, 2019 11:02
Show Gist options
  • Save hergerr/146efcd01bcf4c53b78579b7b9741b55 to your computer and use it in GitHub Desktop.
Save hergerr/146efcd01bcf4c53b78579b7b9741b55 to your computer and use it in GitHub Desktop.
Bytearray to list of lists
def dec_to_bin(lst):
bin_matrix = []
# kazda wartosc ma nowy wiersz w macierzy
for i in lst:
bin_matrix.append(list(bin(i)[2:]))
bin_matrix_int = [list(map(int, x)) for x in bin_matrix]
return bin_matrix_int
def bin_to_dec(bin_matrix):
dec_list = []
for bin_list in bin_matrix:
temp = [str(bin_element) for bin_element in bin_list]
temp = ''.join(temp)
dec_list.append(temp)
return [int(number, 2) for number in dec_list]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment