Created
January 4, 2020 17:02
-
-
Save kkt-ee/aa327a6add135c93c4388471a72e4b4f to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
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