PHP Integers

Integer size is platform-dependent, safest is to assume a maximum value of about two billion (32 bits signed).

64-bit platforms usually have a maximum value of about 9E18

Unsigned integers are not supported in PHP

If PHP encounters a number, or the result of an operation, that is beyond the bounds of the integer type, it will be interpreted as a float instead.

Operators you can use

Bitwise AND

  $StatusFlagGpsCommsOk = 0;
  if ($StatusFlags & 0x01)
    $StatusFlagGpsCommsOk = 1;

  $MyValue &= 0x05;

Bit Shift

Doesn’t look like >>= and <<= can be used, but << and >> are valid operators in PHP

  $MyValue = 0x00001;
  $MyValue = $MyValue << 5;

  $MyValue <<= 5;


Bits that are set in $a are not set, and vice versa.

  $MyVariable = ~(0);
  $MyVariable = ~($MyVariable);
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.