Skip to content

Instantly share code, notes, and snippets.

@EdoardoVignati
Created October 20, 2021 21:24
Show Gist options
  • Save EdoardoVignati/99a35b7db796b5e2c336eb24d3f270b6 to your computer and use it in GitHub Desktop.
Save EdoardoVignati/99a35b7db796b5e2c336eb24d3f270b6 to your computer and use it in GitHub Desktop.
Convert bool list to int and vice versa
def convert_bool_array_to_int(bool_array):
to_str_array = [str(int(x)) for x in bool_array]
return int("".join(to_str_array), 2)
def convert_int_to_bool(int_value):
to_byte_string = "{0:b}".format(int(int_value)).rjust(5, "0")
return [x == "1" for x in to_byte_string]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment