怎樣使得一個(gè)數(shù)從右向左4~9位全是1:
int a = 222222;
int temp = ~(~0 << 6);// ~0 使用數(shù)的每一位全為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;
}