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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
goodmorningsky
Forum Newbie
Posts: 11
Joined: Thu Aug 11, 2005 12:40 am

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

Post 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.
ASDen
Forum Commoner
Posts: 55
Joined: Fri Aug 24, 2007 10:27 am

Post 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 ?
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post 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.
Post Reply