Have read the question yet? Read it here.
ORIGINAL = 00111 SHIFT RIGHT = 00011 NOT = 11100 AND with ORIGINAL = 00100
Here's the code:
// Clears all the bits on the given value except // the leftmost bit that was set static ulong KeepHighestSetBit(ulong value) { value |= value>>1; value |= value>>2; value |= value>>4; value |= value>>8; value |= value>>16; value |= value>>32; return value & ~(value>>1); }
Congrats to Raj Kaimal for figuring this out!