I want to do OR operation on binaries. I have the binaries in strings. E.g
>>> 110 | 001
111
I have these binaries as strings. LIke this: '110100' and '001011'
For the above inputs, I want an output : 111111
I want to do OR operation on binaries. I have the binaries in strings. E.g
>>> 110 | 001
111
I have these binaries as strings. LIke this: '110100' and '001011'
For the above inputs, I want an output : 111111
If you have two strings with a binary number inside them, you can simply convert them to base 10 integers and then do your binary operations inside a bin().
num1 = int("110", 2)
num2 = int("001", 2)
print(bin(num1 | num2))
# Prints 0b111
Or for your second example:
num1 = int("110100", 2)
num2 = int("001011", 2)
print(bin(num1 | num2))
# Prints 0b111111
This gives you answers in actual binary numbers inside python. For reference, I recommend this question: Binary numbers in Python
I could do what I want like this. May be there are simpler ideas.
>>> eval('0b' + '110100') | eval('0b' + '001011')
63
>>> bin(63)
'0b111111'