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);
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.


Your email address will not be published.