Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a 32bit integer on a 64bit installation of PHP?

Tags:

php

int

I run into a problem on my code when moved to production because the production server is 32bit while my development machine is 64bit (I'm running Kubuntu 12.04 64bit). My question is. Is it possible to force an int to be 32bit without installing the 23bit version of PHP? Either that or a library that allow me to chose the max int value

like image 964
Yohan Leafheart Avatar asked Mar 21 '13 20:03

Yohan Leafheart


People also ask

Is integer 32-bit or 64-bit?

int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size.

What is the limit of PHP integer value?

PHP's integer type has always been a 32-bit signed integer with a maximum value of 2,147,483,647.

How do I run a 32-bit integer in Python?

The int data type in python simply the same as the signed integer. A signed integer is a 32-bit integer in the range of -(2^31) = -2147483648 to (2^31) – 1=2147483647 which contains positive or negative numbers. It is represented in two's complement notation.


1 Answers

Integers are the size of pointers on that platform. (32-bit PHP --> 32-bit integers. 64-bit PHP --> 64-bit integers).

Note that when integer operations overflow, the variables become floats. The PHP documentation explains all of this well.

I'm not sure what you're doing in your code that would cause you to care what size the integer is though. If you only care about 32-bits of a value, however, you can always mask off the low 32 bits:

$val = $something & 0xFFFFFFFF;
like image 58
Jonathon Reinhart Avatar answered Nov 03 '22 05:11

Jonathon Reinhart