There is a file base/Bits.h which contains that kind of bits operations. It could be interesting to add a MostSignificantBit, then this function  is 1 << (1+MostSignifcantBit( n-1 ) ).