Now, I know the way to set the i'th bit of a number is use the shift operator to shift 1 till you reach the required bit, and then just or it with the number. But this process is O(length of number) because shifting a number to the i'th position is like traversing until there, right? Please correct me if I'm wrong.
Here is my code:
x = x| (1<<i)
Is there a way to do this in O(1)? In other words, how does one get direct access to the bits in a number? I'm thinking along the lines of array indexing.