1、右移
2 >> 1:相当于2/2。
99 >> 1: 相当于 99/2 向下取整为49。
99 >> 2:相当于 99/pow(2,2)向下取整为24。
999 >> i:相当于999 / pow(2,i)。
整数 >> i:相当于将这个整数化为二进制整数,并去掉这个数的末尾的 i 位数字。
cout << (2 >> 1) << endl;
// 1
cout << (99 >> 1) << endl;
// 49
cout << (99 >> 2) << endl;
// 24
cout << (999 >> 3) << endl;
// 124
cout << (1000 >> 4) << endl;
// 62
2、左移
2 << 1:相当于2*2。
99 << 1: 相当于 99*2 。
99 << 2:相当于 99*pow(2,2)。
999 << i:相当于999 * pow(2,i)。
整数 << i:相当于将这个整数化为二进制整数,并在这个数的末尾加上 i 个0。
cout << (2 << 1) << endl;
// 4
cout << (99 << 1) << endl;
// 198
cout << (99 << 2) << endl;
// 396
cout << (999 << 3) << endl;
// 7992
cout << (1000 << 4) << endl;
// 16000
3、数字1 << 左移
1 << i = pow(2,i)
cout << (1 << 0) << endl;
// 1
cout << (1 << 1) << endl;
// 2
cout << (1 << 2) << endl;
// 4
cout << (1 << 3) << endl;
// 8
cout << (1 << 4) << endl;
// 16
2 << i = pow(2,i) * 2
3 << i = pow(2,i) * 3
x << i = pow(2,i) * x