f



Right Shift

Here's some confusion for you...

<?PHP
 $x = (4653896912 >> 13);
echo $x;
?>

I ran that on two different servers.

Server A gave me: 43814
Server B gave me: 568102

I have been hacking away and researching this for hours. I am
completely clueless. Any suggestions or workarounds? Thanks in advance.

0
agotterer (10)
3/15/2006 10:32:38 AM
comp.lang.php 32646 articles. 0 followers. Post Follow

10 Replies
547 Views

Similar Articles

[PageSpeed] 25

I just figured out that server A is a 32 bit machine and server B is
64. How can I account for this?

0
agotterer (10)
3/15/2006 10:45:15 AM
CrashRoX said the following on 15/03/2006 10:32:
> Here's some confusion for you...
> 
> <?PHP
>  $x = (4653896912 >> 13);
> echo $x;
> ?>
> 
> I ran that on two different servers.
> 
> Server A gave me: 43814
> Server B gave me: 568102
> 
> I have been hacking away and researching this for hours. I am
> completely clueless. Any suggestions or workarounds? Thanks in advance.
> 

4653896912 is bigger than can be represented as a signed-int on a 32-bit 
platform, so gets truncated to 358929616.  And (358929616 >> 13) == 43814.

However, 4653896912 can be represented as a signed-int on a 64-bit 
platform, giving the "correct" answer of 568102.


[NOTE: I haven't checked this to see if it's right though...]

-- 
Oli
0
catch (918)
3/15/2006 10:45:55 AM
Im actually looking for the answer as 43814. Is there no "workaround"
or solution to force a 64 bit machine to generate the same answer?

0
agotterer (10)
3/15/2006 10:48:27 AM
CrashRoX said the following on 15/03/2006 10:48:
> Im actually looking for the answer as 43814. Is there no "workaround"
> or solution to force a 64 bit machine to generate the same answer?
> 

Why are you looking for this to be the answer?  In some senses, 
(4653896912 >> 13) is meaningless on a 32-bit machine.

However, I guess you could do:

$x = 4653896912;
$y = $x & 0xFFFFFFFF;
$z = $y >> 13;

I can't confirm that this will work though, as I don't have access to 
64-bit PHP...

-- 
Oli
0
catch (918)
3/15/2006 12:18:25 PM
CrashRoX wrote:
> I just figured out that server A is a 32 bit machine and server B is
> 64. How can I account for this?
> 

Don't count on values larger than the maximum integer size!  It just 
creates more bugs.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
jstucklex (14659)
3/15/2006 12:36:55 PM
I know the actual results are meaningless for a 32-bit system. Im
dealing with an application that was designed on a 32bit system and is
being ported to 64. Unfortunately the system was designed to use
results generated from the 32-bit system, regardless if it has meaning.
Oli Filth's suggestion seems to be working. Hopefully it will hold up.

Thank you.

0
agotterer (10)
3/15/2006 7:15:39 PM
The right "workaround" seems to be doing the job. Will this work the
same way going left?

	$x = $a;
	$y = $x & 0xFFFFFFFF;
	$z = $y << $b;
	
	return $z;

0
agotterer (10)
3/15/2006 8:36:07 PM
I believe I narrowed down my bug to ZOR. The right and left shifts
seems to be working just fine with the workaround suggested. Any
suggestions for a ZOR workaround?

0
agotterer (10)
3/15/2006 8:49:40 PM
I believe I narrowed down my bug to XOR. The right and left shifts
seems to be working just fine with the workaround suggested. Any
suggestions for a XOR workaround?

0
agotterer (10)
3/15/2006 8:50:41 PM
I believe I narrowed down my bug to XOR. The right and left shifts
seems to be working just fine with the workaround suggested.

$b ^= $c

is giving me different results on the 32bit machine and the 64. Im
looking to get the same 32bit answer on the 64bit machine. Any
suggestions for another workaround?

0
agotterer (10)
3/15/2006 9:21:05 PM
Reply: