Page 1 of 1

Try this statement and check if it works on your machine!

Posted: Fri Oct 19, 2007 2:13 pm
by goodmorningsky
Hi, all.
Try following PHP code

Code: Select all

<?php echo 2022886285 & -2147483649; ?>
[/b]
It should return 2022886285

- On my current Web hosting: It works OK.
IXWebhosting.com
Dell PowerEdge 2650
DUAL Intel Xeon 2.8GHz, 512K Cache
RedHat - 7.3 OS on your server

- On my new Dedicated Web hositn: It return just 0. Problem!
HostGator.com
Pentium 4 2.4Ghz
CentOS Enterprise.

Why One simple Bitwise statement doesn't work on CentOS?

New Hosting company support from HostGator tells me
It's code problem or php problem.
However it works on others.

Please test the statement in your site and Reply the result if it returns proper value or not.

It helps me alot and helps others facing this problem.

Posted: Fri Oct 19, 2007 8:57 pm
by ASDen
Working on windows xp
But i think an important Question is ur php version i'm using 5 and probably u what about the host ?

Posted: Fri Oct 19, 2007 9:04 pm
by mrkite
It's caused by the buggy way that PHP handles numbers above 0x7fffffff

Code: Select all

$a=0x7fffffff;
$a=-$a;
printf("%x\n",$a);  // prints 0x80000001
$a=0x80000001;
$a=-$a;
printf("%x\n",$a); //prints 0x80000000
When you set $a to a number above 0x7fffffff, PHP does everything it can to treat it as a positive integer... so trying to negate it causes an overflow.

The solution? Don't use numbers with the high bit set.