One idea for "bit operations", take a random example i = "0..0100101":
Step1: right shift i by 1 -> "0..0010010"
Step2 : bitwise OR -> "0..0110111" and take this as new i
Step3: repeat Step 1 and 2 until all bits after highest "1" bit are all "1", i.e., i should be "0..0111111"
Step4 : right shift i by 1 -> "0..0011111" and flip all bits (I'll call this j)
Now we have
i: 0..0111111
j: 1..1100000
It should be clear by now how to get the highest "1" bit.
reference: https://habr.com/ru/post/93172/
Is this allowed?
How do you repeat without a loop or without exceeding the size of the number?
My single line solution below works but it fails verification because I am using things I am not allowed apparently.
GO TO FULL VERSION