I couldn't find a proper solution to this simple question in Bitset methods. The question is to find the common parent of bitsets, starting from the left most bit. Here are some examples:
011
010
001
Common Parent: 0
00
010
Common Parent: 0
00
11
10
Common Parent: None
1101
111
1100
Common Parent: 11
My solution was to AND the Bitsets, and then find the correct length by looking for the first set bit on XOR of these Bitsets. It worked for some cases but failed for others. I have another idea which involves looping over the Bitsets which I would be very happy to avoid if you have a solution.
[I know that they can be presented as a binary tree, but that involves a memory overhead which I would like to avoid by operating only over the bitsets and some boolean operations (AND, OR, NOR, NAND, XOR)]