i want to check whether the sum of 2 binary list equals to another binary list
[1, 0, 1] + [0, 1, 1] == [1, 1, 1]
how do i go about doing that in python? tried using numpy but it doesn't work
You can convert decimal to binary using function bin()
:
num1 = 2
num2 = 3
res = bin(num1 + num2)
print(res)
you can try this:
list(map(lambda x, y: x+y, [1, 0, 1] , [0, 1, 1]))==[1, 1, 1]
you can try to do something like that:
result = bin([1, 0, 1] + [0, 1, 1])
print([1, 1, 1] == result)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.