>> and << shift bits, not bytes. Numbers are internally
represented in digital computers using two-state bits.
The bitshift operators shift these bits.
For example 7 is 111 in binary. Shifting it one place left
results in 1110 (digits coming from off the edge are zero),
or 14. 111b shifted right once is 11 (a bit is shifted
off), or 3. 7*2=14, and 7/2 is 3.5, the .5 is lost because
of the one being shifted off.
Hope this helps.
A byte is 8 bits. A bit is a 1 or a 0 that spells out the
binary number corresponding to what you're trying to express.
2 in binary is 00000010. Shifting that to the left by
3 is this:
2 << 3 which yeilds 00010000 which is 8.
shifting bits is like taking an eight bit number and rotating
it in a certain direction.
2 << 4 is 2 "left shifted" by four digits. In binary, 10.00000 is moved four digits to the left to result in 100000.0, or 32. Every time you move the decimal point in binary, you multiply or divide by two. So it's like moving the decimal point to multiply or divide by ten in decimal.