「算法竞赛进阶指南」 0x01 位运算 知识笔记

二进制是计算机的根本!

你了解它吗?

int lowbit(int x)
{
    return x&(-x);//x&(~x+1),~x=-1-x;
}
int __builtin_ctz(unsigned int x)
int __builtin_ctzll(unsigned long long x)
返回x的二进制表示下最低位的1后面有多少个0 
int __builtin_popcount(unsigned int x)
int __builtin_popcountll(unsigned long long x)
返回x的二进制表示下有多少位为1 

猜你喜欢

转载自www.cnblogs.com/hovny/p/10133612.html