I was asked this question in an interview to clear m bits after n bits from a 16-bit integer.
Suppose this number is 10010010010100101. Reset three bits after 5 bits from LSBit.
Before: 10011001 110 11001 After: 10011001 000 11001
My mask solution was (~0 << (m+n))+((1<<n)-1)
Is there any solution better than this?
source
share