How to cast signed to unsigned int for 32-bit in php

3

I have tried to cast signed int to unsigned int for 32-bit in php. but i could not able to get the absolute value for the unsigned int.

example:

 $value = 65547;
  if (PHP_INT_SIZE == 8)
   {
    if ($value>0x7FFFFFFF)
    {
      $value-=0x100000000;
    }
   }

Is any other possibilities to cast signed integer value to unsigned integer value?

php
asked on Stack Overflow Aug 25, 2018 by Nandhini Dheenan • edited Aug 25, 2018 by Dmitry Smorzhok

1 Answer

1

http://php.net/manual/en/function.gmp-abs.php

For php7 you will need the php7.0-gmp package

For php5 you will need the php5-gmp package

var_dump((int) gmp_abs("0x7FFFFFFF"));

... returns

int(2147483647)
answered on Stack Overflow Aug 25, 2018 by Jamie_D • edited Aug 25, 2018 by Jamie_D

User contributions licensed under CC BY-SA 3.0