Can someone explain Shl and Shr please

BlitzMax Forums/BlitzMax Beginners Area/Can someone explain Shl and Shr please

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

First some binary. We usually count with base 10, that is we have 10 digits to make numbers with, so we go in order 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, then we start adding them together to go beyond 10 numbers: 10, 11, 12, 13, etc.

I hope everyone can count. ;-)

In binary though, we only have 2 digits to use: 0 and 1. So the same numbers go like this: 1, 10, 11, 100, 101, 110, etc.

Read more on that here: http://en.wikipedia.org/wiki/Binary_numeral_system

decimal = binary
1 = 00000001
2 = 00000010
4 = 00000100


Okay?

So 1 Shl 1 means shift all the bits in the provided value (in this case 1), 1 spot the left, and chop of the extra zero. So 1 Shl 1 = 2 because when you move those bits to the left you get the same binary number for 2.

1 Shl 1 =   0|00000010 (decimal 2)
2 Shl 1 =  00|00000100 (decimal 4)