a << i
is the same as a * pow(2, i)
<<
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
unsigned int a = 5, b = 48;
for (int i = 0; i < 10; i++) {
cout << (a << i) << " " << a * pow(2, i) << endl;
}
return 0;
}
/*
5 5
10 10
20 20
40 40
80 80
160 160
320 320
640 640
1280 1280
2560 2560
*/
a >> i
is the same as a / (int)pow(2, i)
>>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
unsigned int a = 48;
for (int i = 0; i < 10; i++) {
cout << (a >> i) << " " << a / (int)pow(2, i) << endl;
}
return 0;
}
/*
48 48
24 24
12 12
6 6
3 3
1 1
0 0
0 0
0 0
0 0
*/