Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Integer Shifting...

Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
11-26-2008 13:47
So I'm doing some integer shifts in some scripts ... and I'm finding one particular location in which the shift doesn't seem to be working at all.

Funny thing is ... it's working in other places where the same integer is shifted the same way ...

CODE


//In this situation, the following has already been tested/discovered:
//int = 0
//x = 16843009
//Result SHOULD be y = 4
//Result shows as y = 1
//Doing an llOwnerSay on the equation returns 1 0 0 0
//Removing the variables from the equation and running it with hard-numbers returns 1 1 1 1
//Checking the variables to ensure they're the right value returns the correct value

if(int < 8) y = (((x << int) & 0x01) + ((x << (int + 8)) & 0x01) + ((x << (int + 16)) & 0x01) + ((x << (int + 24)) & 0x01));



Can anyone spot what's wrong? I'm pulling my hair out.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
11-26-2008 14:33
The result SHOULD be one. Any time you left-shift a number the result will be even (a binary zero is shifted in on the "right", or least significant bit). So the only addend that will be non-zero is the first one where you shift by zero bits, and the result of the bitwise AND for that will be 1.
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
11-27-2008 07:28
The solution to the issue was to remove the most outside bracket of parentheses ... then it all came together and gave me the proper result of 4.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
11-28-2008 09:08
Did you mistype the right-shift operator (>>;) as left-shift operator (<<;)?