I was going to Cracking the Coding Interview chapter 5 Bit manipulation and found way to clear bits from i through 0 in number num
int mask = ~(-1 >>> (31 - i));
return num & mask
Though the above works
Can we make it simple like
int mask = (-1 << (i+1));
return num & mask;
Am I missing any corner cases ?