From: helpmepro1 at gmail dot com Operating system: linux PHP version: 5.2.8 PHP Bug Type: Scripting Engine problem Bug description: xor,~ bitwise operations are not 32 bit
Description: ------------ the problem is doing bitwise operations with large numbers like larger then 28 bit. when i do negative bitwise operation "~" to 4738698913 in binary 11010011100101100111010100001{29bit} the number becomes binary 10000000000000000000000000000000{32bit} expected: 11100101100011010011000101011110 Reproduce code: --------------- <TEXTAREA STYLE="height:98%;width:98%"> <?php // //I think I found out the solution by using GMP function. //Code: function gxor($a,$b) { $a=gmp_init("$a",10); $b=gmp_init("$b",10); return gmp_strval (gmp_xor ($a, $b),10); } echo "gxor(-5799680607,167160) = ".gxor(-5799680607,167160)."\n"; echo " as expected -5799843495 \n"; echo " -5799680607^167160 = " .(-5799680607^167160)."\n"; echo " wrong result \n\n"; echo "var_dump(-4738698913) = "; var_dump(-4738698913); echo "so this number is float\n\n"; echo "A decbin 43814 SIMPLE = ".decbin(43814)."\n\n"; //a echo "B decbin -4738698913 NOT WORKING = ".decbin(-4738698913)."\n\n"; //b echo "C decbin 4738698913 SIMPLE = ".decbin(4738698913)."\n\n"; echo "D decbin abs -4738698913 WORKING = ".decbin(abs(-4738698913))."\n\n"; echo "E decbin ~abs -4738698913 NOT WORKING = ".decbin(~abs(-4738698913))."\n\n"; echo "F decbin ~abs -1738698913 WORKING = ".decbin(~abs(-1738698913))."\n\n"; echo "G decbin ~ -4738698913 64bit expected result: 1111111111111111111111111111111011100101100011010011000101011110\n"; echo "H the 64bit bitwise not is from windows calc.exe\n\n"; echo "from the B and G example i can deduce that php takes the left side of 64 bit integer instead of the right and returns it as 32 bit (just a guess)\n\n"; // 1111111111111111111111111111111011100101100011010011000101011110 echo "php version ".PHP_VERSION; echo "\n"; echo `cat /proc/version`; echo "\n"; echo `cat /proc/cpuinfo`; echo "\n"; ?> </TEXTAREA> Expected result: ---------------- gxor(-5799680607,167160) = -5799843495 as expected -5799843495 -5799680607^167160 = -2147316488 wrong result var_dump(-4738698913) = float(-4738698913) so this number is float A decbin 43814 SIMPLE = 1010101100100110 B decbin -4738698913 NOT WORKING = 10000000000000000000000000000000 C decbin 4738698913 SIMPLE = 11010011100101100111010100001 D decbin abs -4738698913 WORKING = 11010011100101100111010100001 E decbin ~abs -4738698913 NOT WORKING = 1111111111111111111111111111111 F decbin ~abs -1738698913 WORKING = 10011000010111011000111101011110 G decbin ~ -4738698913 64bit expected result: 1111111111111111111111111111111011100101100011010011000101011110 H the 64bit bitwise not is from windows calc.exe from the B and G example i can deduce that php takes the left side of 64 bit integer instead of the right and returns it as 32 bit (just a guess) Actual result: -------------- php version 5.1.6 Linux version 2.6.18-92.1.18.el5PAE (mockbu...@builder16.centos.org) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Wed Nov 12 10:02:30 EST 2008 processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 23 model name : Intel(R) Xeon(R) CPU E5405 @ 2.00GHz stepping : 6 cpu MHz : 1995.120 cache size : 6144 KB physical id : 0 siblings : 4 core id : 0 cpu cores : 4 fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 10 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx tm2 cx16 xtpr lahf_lm bogomips : 3992.34 -- Edit bug report at http://bugs.php.net/?id=47246&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47246&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47246&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47246&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47246&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47246&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47246&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47246&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47246&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47246&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47246&r=support Expected behavior: http://bugs.php.net/fix.php?id=47246&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47246&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47246&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47246&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47246&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47246&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47246&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47246&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47246&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47246&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47246&r=mysqlcfg