Page 1 of 1

Shr and Shl dont work as expected

PostPosted: Wed Nov 17, 2010 7:46 am
by udo.killermann
Bernd,

when I run the following code it works counter-intuitive to the things I learned with C and Assembler:

Code: Select all
Event AwakeFromNib()
  Dim myInt As Integer
  Dim result As Integer
 
  myInt = 0x1f
  result = myInt Shr 4 ' I expect to get 0x01
  Log("result: ",Hex(result))
 
  result = myInt Shl 4 ' I expect to get 0x1f0
  Log("result: ",Hex(result))

End Event


The output reads:
Code: Select all
result:  1F0
result:  1


Shr means to me: move the bit pattern to the right, in direction of the least significant bits (the value should decrease using this operator)
Shl means to me: move the bit pattern to the left, in direction of the most significant bits (the value should increase using this operator)

I thinks this is an error in the runtime.

Regards
Udo