power of 2 or not

来源:互联网 发布:p2p网络借贷系统 编辑:程序博客网 时间:2024/05/29 03:33
int ispowerof2(unsigned int x) {   return x && !(x & (x - 1));}


Note that the bit pattern of a power of two is of the form 10...0 and that of a number just one less is 011...1.

原创粉丝点击