本文共 388 字,大约阅读时间需要 1 分钟。
Write a C function that unsets the rightmost set bit of an integer.
Let the input number be n. n-1 would have all the bits flipped after the rightmost set bit (including the set bit). So, doing n&(n-1) would give us the required result.
/* unsets the rightmost set bit of n and returns the result */int fun(unsigned int n){ return n&(n-1);}
转载地址:http://mexti.baihongyu.com/