This makes sure 4 bits ( From MSB and including MSB ) are set
n |= n >> 2 NEW_LINE n |= n >> 4 NEW_LINE n |= n >> 8 NEW_LINE n |= n >> 16 NEW_LINE return n NEW_LINE def toggle ( n ) : NEW_LINE n = n ^ setAllBitsAfterMSB ( n ) NEW_LINE return n NEW_LINE