需要研究:
#include <iostream> using namespace std; int main(){ int a = 1, b = 32; cout << (a << b) << endl; cout << (1 << 32) << endl; system("pause"); return 0; }
算一个数的二进制里有多少个1: x&(x-1)
#include <iostream> using namespace std; int func(int x) { int countx = 0; while (x) { countx++; x = x&(x - 1); } return countx; } int main(){ int i; i = func(65530); cout << i; system("pause"); return 0; }
二进制数 第n位是0还是1?
#include <iostream> using namespace std; unsigned int func(int num, int indexBit) { num = num >> indexBit; return num&1; } int main(){ int i; i = func(65530,0); cout << i; system("pause"); return 0; }