怎样使得一个数从右向左4~9位全是1:
int a = 222222;
int temp = ~(~0 << 6);// ~0 使用数的每一位全为1, 左移六位,使得最右边6位全为0, 再取反,例前面全为0,后面6位为1.
a >>= 4;
a &= temp;
a <<= 4;
32 bits binary nummer:
#include <iostream>
using namespace std;
int main() {
int ref = 1 << 31;
int a = 14;
for (int i = 0; i < 32; i++) {
cout << (a & ref? '1': '0');
a <<= 1;
}
return 0;
}