>>
is the right bit-shift (a) which shifts all bits in a value right by a given value. For unsigned integers, >> 1
is effectively an integral divide by two.
The value 18 in binary is:
0001 0010
| |
| +--- 2
+------- 16
--
18
Right-shifting that by one bit position (bits "drop off" the right hand side and 0
bits come in from the left) gives you:
0000 1001
| |
| +-- 1
+----- 8
--
9
(a) It is in this particular case. C++ also allows for >>
to be used as an operator for classes, such as with std::cin >> myInputVar;
which will attempt to read a value from standard input and place it into the myInputVar
variable.