So, I'm reading a book on Go (The Way to Go by Ivo Balbaert), and in it there is a code sample:
const hardEight = (1 << 100) >> 97
Since I don't have Go installed on this machine, I decided to translate it to PHP to see the results (via http://writecodeonline.com/php/ since I don't have PHP installed on this machine either):
echo (1 << 100) >> 97;
The result for the above is 8
....huh? So I wrote decided ok, lets write a for-loop from 0 to 100 and see the results:
for($i = 0; $i <= 100; $i++){
echo $i . ": ";
echo ($i << 100) >> 97;
echo "<br>";
}
However, the results are:
0: 0
1: 8
2: 16
3: 24
4: 32
5: 40
6: 48
7: 56
8: 64
9: 72
10: 80
11: 88
12: 96
13: 104
14: 112
15: 120
16: 128
17: 136
18: 144
19: 152
20: 160
21: 168
22: 176
23: 184
24: 192
25: 200
26: 208
27: 216
28: 224
29: 232
30: 240
31: 248
32: 256
33: 264
34: 272
35: 280
36: 288
37: 296
38: 304
39: 312
40: 320
41: 328
42: 336
43: 344
44: 352
45: 360
46: 368
47: 376
48: 384
49: 392
50: 400
51: 408
52: 416
53: 424
54: 432
55: 440
56: 448
57: 456
58: 464
59: 472
60: 480
61: 488
62: 496
63: 504
64: 512
65: 520
66: 528
67: 536
68: 544
69: 552
70: 560
71: 568
72: 576
73: 584
74: 592
75: 600
76: 608
77: 616
78: 624
79: 632
80: 640
81: 648
82: 656
83: 664
84: 672
85: 680
86: 688
87: 696
88: 704
89: 712
90: 720
91: 728
92: 736
93: 744
94: 752
95: 760
96: 768
97: 776
98: 784
99: 792
100: 800
Can someone explain to me what is going on with the snippet? I know its bitshifting, but I don't understand bitshifting well enough to discern what is going on there. Thank you :)