Skip to content

Instantly share code, notes, and snippets.

@kkt-ee
Created January 4, 2020 17:02
Show Gist options
  • Save kkt-ee/aa327a6add135c93c4388471a72e4b4f to your computer and use it in GitHub Desktop.
Save kkt-ee/aa327a6add135c93c4388471a72e4b4f to your computer and use it in GitHub Desktop.
"""
Given an array of ones and zeroes, convert the equivalent binary value to an integer.
Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.
"""
def binary_array_to_number(arr):
# your code
return int(''.join([str(x) for x in arr]),2)
#OR
def binary_array_to_number(arr):
return int("".join(map(str, arr)), 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment