Created
October 20, 2021 21:24
-
-
Save EdoardoVignati/99a35b7db796b5e2c336eb24d3f270b6 to your computer and use it in GitHub Desktop.
Convert bool list to int and vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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