Skip to the content of the web site.

Project Y.5: Trailing bit manipulations

fill from lowest zero bitset all 1s after the last 0 to 0
isolate lowest zero bitset all bits other than the lowest cleared bit to 1
isloate lowest zero bit and complementreplace the lowest zero bit with 1 with all other bits set to 0
mask from lowest zero bitX
set lowest zero bitset the lowest zero bit to 1
fill from lowest one bitset all zero bits after the last 1 to 1
isloate lowest one bit and complementset all bits to 1 except for the lowest 1 bit
inverse mask from trailing onesX

See Wikipedia.

unsigned int to_be_done( unsigned int value );

Templated

template <typename T>
T to_be_done( T value );