3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "int cast: ",-( (int)((2 ** 32) - 0xffffffff)); // -1 echo "int cast: ", (int)(0xffffffff - (2 ** 32)); // -1 printf("\nprintf: %d\n", -((int) (2 ** 32) - 0xffffffff)); // treat as a signed number -- first gets cast to an int? echo "hexdec: "; var_dump((int) hexdec("ffffffff")); printf("\nprintf max int in hex: %x\n",PHP_INT_MAX); echo 0x5,"\n"; echo ~0x5 + 1,"\n"; // transform to -5 $n = sprintf("0x%x", (pow(2,32) - 5) ); // get 2s complement var_dump($n); $i = intval($n + 0); // trick that doesn't work anymore with PHP 7 echo $i; var_dump($i); printf("%x",$i); // display binary as hex $r = 0xffffffff & 0xfffffffb; // anding to simplify var_dump($r); echo 0xfb - pow(2,8); // to detect value of hex printf("\n%x\n",(pow(2, 32) - 5)); echo (5 + 0xfffffffb) == pow(2,32)? 'true':'false'; // floats both echo "\n",0xfffffffb > 0x7fffffff? 'true':'false';
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
int cast: -1int cast: -1 printf: -1 hexdec: int(4294967295) printf max int in hex: 7fffffffffffffff 5 -5 string(10) "0xfffffffb" Warning: A non-numeric value encountered in /in/EkfSn on line 15 0int(0) 0int(4294967291) -5 fffffffb true true
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
int cast: -1int cast: -1 printf: -1 hexdec: int(4294967295) printf max int in hex: 7fffffffffffffff 5 -5 string(10) "0xfffffffb" Notice: A non well formed numeric value encountered in /in/EkfSn on line 15 0int(0) 0int(4294967291) -5 fffffffb true true
Output for 7.0.0 - 7.0.33, 7.3.32 - 7.3.33
int cast: -1int cast: -1 printf: -1 hexdec: int(4294967295) printf max int in hex: 7fffffffffffffff 5 -5 string(10) "0xfffffffb" 0int(0) 0int(4294967291) -5 fffffffb true true
Output for 5.6.0 - 5.6.38
int cast: -1int cast: -1 printf: -1 hexdec: int(4294967295) printf max int in hex: 7fffffffffffffff 5 -5 string(10) "0xfffffffb" 4294967291int(4294967291) fffffffbint(4294967291) -5 fffffffb true true
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '*' in /in/EkfSn on line 3
Process exited with code 255.

preferences:
153.67 ms | 411 KiB | 5 Q