The naïve method of reversing the bits in a number copies the bits one-by-one in a loop, or alternatively, swaps them two-by-two. This algorithms is O(*n*) where *n* is the number of bits.

However, there is an O(log *n*) method (when *n* is a power of 2); rather than taking *n* or *n*/2 steps, it takes log_{2}(*n*) steps.