php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30970 32bits not supported?
Submitted: 2004-12-03 00:46 UTC Modified: 2004-12-03 05:57 UTC
From: wboring at qualys dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.2 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wboring at qualys dot com
New email:
PHP Version: OS:

 

 [2004-12-03 00:46 UTC] wboring at qualys dot com
Description:
------------
If I set an integer to a value of 0x80000000, it works properly in php4, but in php5 the value becomes 0x7FFFFFFF.


My configure line:
./configure \
--with-oci8=/u01/app/oracle/product/8.1.7 \
--enable-sigchild \
--with-mcrypt \
--with-gd \
--with-png-dir=/usr \
--with-jpeg-dir=/usr \
--with-zlib-dir=/usr \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--with-xml \
--with-zlib \
--with-gdbm \
--with-dom \
--with-curl=/usr \
--with-mysql=/usr \
--enable-mbstring \
--enable-tokenizer \
--enable-sockets \
--with-kerberos=/usr/kerberos \
--with-openssl \
--disable-cgi \
--with-xsl \
--with-bz2 \
--with-mhash \
--enable-soap \
--with-flatfile \
--with-inifile \
--with-curlwrappers \
--with-apxs=/usr/local/apache/bin/apxs







Reproduce code:
---------------
<?php
  $n = 0x80000000;
  printf('%b', $n);
?>


Expected result:
----------------
php4.3.9: 10000000000000000000000000000000
php5.0.2: 10000000000000000000000000000000
 

Actual result:
--------------
php4.3.9: 10000000000000000000000000000000
php5.0.2: 1111111111111111111111111111111

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-03 01:36 UTC] wboring at qualys dot com
If I do a simple var_dump( 0x80000000 ); in php4 and 5 I get the same result of float(2147483648).

If I try and do something like

$n ^= 0x80000000;  //to flip the high bit, then it breaks.

<?php 
  $n = -1979053311;
  var_dump( sprintf('%32b',$n).'  '.$n);
  $n ^= 0x80000000; // flip the high (sign) bit
  var_dump( sprintf('%32b',$n).'  '.$n );
?>

php4.3.9 : 
string(45) "10001010000010100000101100000001  -1979053311"
string(43) "    1010000010100000101100000001  168430337"

php5.0.2 :
string(32) "10001010000010100000101100000001  -1979053311" 
string(44) "11110101111101011111010011111110 -168430338"
 [2004-12-03 05:57 UTC] pollita@php.net
Yes PHP supports 32-bit ints, but the higest bit is a sign, so the largest meaningful int *IS* 0x7FFFFFFF, after that the number must be expressed as a float, attempting to express as a long results in "undefined behavior".

5.0.2 introduced a patch to truncate float to lval conversion to no more than 0x7FFFFFFF.  Don't worry, it's been reverted.  Take a look at 5.0.3RC1 or a snapshot from snaps.php.net

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 14:01:36 2025 UTC