php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #34370 intval fails on negative hex numbers
Submitted: 2005-09-05 00:32 UTC Modified: 2005-09-05 12:18 UTC
From: andreybl at matrix dot co dot il Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5CVS-2005-09-05 (snap) OS: RH EL 3.0
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: andreybl at matrix dot co dot il
New email:
PHP Version: OS:

 

 [2005-09-05 00:32 UTC] andreybl at matrix dot co dot il
Description:
------------
inval() for negative hex number returns the max integer value.



Reproduce code:
---------------
$hex1 = intval("0xffffffff", 16);
$hex2 = intval("0x7fffffff", 16);
var_dump($hex1, $hex2);


Expected result:
----------------
int(-1)
int(2147483647)

Actual result:
--------------
int(2147483647)
int(2147483647)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-05 08:56 UTC] sniper@php.net
Documentation should state this more clearly.
 [2005-09-05 10:57 UTC] vrana@php.net
0xffffffff isn't negative, it's 4294967295 which is over limit so 2147483647 is returned according to documentation.
 [2005-09-05 12:18 UTC] andreybl at matrix dot co dot il
Actually 0xffffffff is neither negative nor positive. It depends upon how we treat it: as signed or as unsigned.

Ok. Should I close the bug?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 08:01:29 2025 UTC