Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shr/shl
#1
what do these do?

no offense wt, but im kinda tired of looking at the wikis you post. i would just like a simple explanation this time. :wink:
Reply
#2
SHL = SHift Left
SHR = SHift Right

Shifts an integral number by a given number of bits.

Example:
Code:
print 1 shl 4 ' outputs 16

'x SHL y' is mathematically the same as 'x * 2 ^ y' for every y>=0 and 'x SHR y' is mathematically the same as 'fix(x / 2 ^ y)' for every y>=0.

Regards,
Mark
Reply
#3
Visual representation
2:
00000000 00000000 00000000 00000010
2 shl 1:
00000000 00000000 00000000 00000100
2 shr 1:
00000000 00000000 00000000 00000001

edit: assuming a 32 bit number is used
[Image: freebasic.png]
Reply
#4
Thank u mjs and deleter for that quick as hell explanation.

cross my heart.
Reply
#5
np, hope all works out well
[Image: freebasic.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)