Furthermore, Take a look at:

Arithmatic Operators in C++



The function itself can be simplified much more but the biggest reason ppl use C++ is that extra push of speed and efficiency so doing: mask = mask / 2; is not as fast as mask >>= 1; bitwise operators are extremly fast because all they do is take a look at the binary number and do a fast "switching" of bits (on/off).