Long numbers in PHP

Associate
Joined
30 Dec 2005
Posts
415
Greetings everybody!

I've hit of a problem in PHP, when it comes to dealing with very large numbers.

For example, I have this number stored in a MySQL database - 140737488355330 (bigint 25).

In PHP, I need to do some processing on this number. However, because i'm running the script on a 32bit processor, the number is larger than the maximum possible size for an integer, causing some unexpected results.

Is there any way I can get around this? Is there an alternative number type I can use which has a much greater limit than integer?

Regards,
Rich
 
OK so i've got a simple bit of php, but i'm not sure how to integrate the BC math functions into it...

Any pointers?

PHP:
$mask = 140737488355337;
$permissions = array();
for ($i = 1; $mask > 0; $i <<= 1, $mask >>= 1) {
	if (($mask & 1) == 1) {
		$permissions[] = $i;
	}
}
 
Back
Top Bottom