note 53814 added to function.dechex
| From: | oliver at realtsp dot com | Date: | Tue, 14 Jun 2005 08:46:24 +0000 |
| Subject: | note 53814 added to function.dechex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90396@lists.php.net to get a copy of this message | ||
Warning for use on 64 bit machines! The Extra length matters!
32bit machine:
php -r 'echo dechex(4294967295);'
output: ffffffff
64bit machine:
php -r 'echo dechex(4294967295);'
output: ffffffff
so far it is ok. But for slightly bigger numbers:
32bit machine:
php -r 'echo dechex(4294967296);'
output: 0
64bit machine:
php -r 'echo dechex(4294967296);'
output: 100000000
note the difference!
This is particularly important when converting negative numbers:
64bit machine:
php -r 'echo dechex(-1);'
output: ffffffffffffffff
32bit machine:
php -r 'echo dechex(-1);'
output: ffffffff
If you want your code to be portable to amd64 or xeons (which are now quite popular with hosting
companies) then you must ensure that your code copes with the different length of the result for
negative numbers (and the max value, although that is probably less critical).
----
Manual Page -- http://www.php.net/manual/en/function.dechex.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53814
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53814&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53814&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53814&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53814&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53814&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53814&report=yes
Search -- http://master.php.net/manage/user-notes.php