Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / BUG: Right Shift Operator >> Retains MSB (Sign Bit on Shift)

Author
Message
Muckypaws
AGK Developer
13
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 25th Jan 2015 01:12
HI,

AGK V2.0.10

When using the RightShift Operator on an INTEGER, the MSB or SIGN Bit is retain, so if I had a binary Pattern



I would expect



However I see



The help file doesn't suggest a rotate of the bits 0 - 30 only.

Kind Regards
Jason
www.wonkypix.com

http://itunes.apple.com/us/app/newtons-nonsense/id473520354?ls=1&mt=8
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 25th Jan 2015 08:21
Ah , well, now there's the thing.

Historically processors have two forms of each shift - the logical shift and the arithmetic shift. For left shifts they are identical. For right shifts the arithmetic shift preserves the most significant bit - because it is dividing by 2.

The jolly is that C and C++ do not actually specify what right shifts do for negative numbers (the code is correct in the VM) so it may be a bug and it may be a poorly explained shift. I'm inclined to go with the latter.

I will add it to the bug list.
Muckypaws
AGK Developer
13
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 25th Jan 2015 20:39
Thanks Paul,

Yep I agree with the definitions of the shift, however the documentation doesn't describe it as the arithmetic shift (preserving the MSB), I can work around it, perhaps the VM can support both types of SHIFT? Possibly using >>> for the signed shift, but I think Java treats >>> differently.

I've used Tier 2, but now playing around with Tier 1 to see what I can create as a demo, it's been an interesting learning curve, finding some of the nuances of tier 1 basic.

Thanks for your help!

Jason
www.wonkypix.com

http://itunes.apple.com/us/app/newtons-nonsense/id473520354?ls=1&mt=8

Login to post a reply

Server time is: 2024-11-25 17:40:20
Your offset time is: 2024-11-25 17:40:20