All problems
Bitset Set Operations
Problem
Apply bitwise set operations to two integers used as bitsets.
Each integer's set bits represent a set of small non-negative integers. Compute the union, intersection, and symmetric difference in one pass.
Return [union, intersection, difference], where difference is the XOR.
Hint
Bitwise or, and, and xor correspond exactly to union, intersection, and symmetric difference.
Test cases
case 1
in: [5,3]
expected: [7,1,6]
case 2
in: [0,0]
expected: [0,0,0]
case 3
in: [255,1]
expected: [255,1,254]
case 4
in: [10,12]
expected: [14,8,6]
Starter codePython
def bitset_ops(a, b):
# Your code here
pass4 test cases · run your code against them in the editor