#35874 [Bgs]: base_convert is off on numbers greater than 13 decimal places

From: Date: Wed, 04 Jan 2006 15:31:45 +0000
Subject: #35874 [Bgs]: base_convert is off on numbers greater than 13 decimal places
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969371431@lists.php.net to get a copy of this message
ID: 35874 User updated by: chris at acsi dot ca Reported By: chris at acsi dot ca Status: Bogus Bug Type: Documentation problem Operating System: Windows XP Sp2 PHP Version: 5.1.1 New Comment: Ah, my bad, couldn't see the forest for the trees. In light of the facts, I make the following suggestion then; 1) Update the documentation to reflect the fact that this function is limited as you've pointed out. You may want to include warns in the other similar functions. 2) Propose that somewhere down the road, someone create a new function that is able to work with at least a MySQL BIGINT (8 byte) integer. Thanks, that's the end of my $0.02.. Previous Comments: ------------------------------------------------------------------------ [2006-01-04 10:20:00] mgf@php.net You're confusing bits and bytes. #FFFFFFFFFFFFF is a 6-1/2 byte number, which is 52 bits -- somewhat beyond the 32-bit (4-byte) integer limitation. Maximum value of a signed 32-bit integer is 2147483647 (or 4294967295 unsigned), not even close to the huge number you quote. ------------------------------------------------------------------------ [2006-01-03 13:24:10] chris at acsi dot ca Yes, I'm familiar with processor limitations, but there is no reason why this function should be limited that way. This problem shows up with a number of 8 bits at maximum size (18446744073709551615 dec unsigned). You can also get the problem with a number of FFFFFFFFFFFFF hex unsigned, which is between 4 and 8 bits. What type of math is the function doing that an 8 bit number is being mangled by a 32 bit OS/CPU limitation? The documentation does not mention any limitation, so either the documentation should be updated to reflect it's limitations (which is a cop out), or the logic should be updated to follow something similar to the many posts people have left under the base_convert() manual entry. Am I missing something here? It still sounds like the function is broken. ------------------------------------------------------------------------ [2006-01-03 02:04:01] chris at acsi dot ca Description: ------------ base_convert($str, 10, 16) will not function properly with numbers greater than 13 characters. Reproduce code: --------------- -BEGIN SCRIPT- $string=(string)"Hello Kitty".(string)time(); $hash=md5($string); $hash=strtoupper($hash); // Easier to Read echo("<br>1Hash is '$hash'<br>"); settype($hash, "string"); echo("<br>2Hash is '$hash'<br>"); $hash=base_convert($hash, '16', '10'); // Flick the string from hex to dec echo("<br>3Hash is '$hash'<br>"); $hash=base_convert($hash, '10', '16'); $hash=strtoupper($hash); echo("<br>4Hash is '$hash'<br>"); // Flick the string back $hash=strtoupper($hash); // Easier to read echo("<br>5Hash is '$hash'<br>"); -END SCRIPT- Expected result: ---------------- I can't show the exact expected number, as my MS Calc in hex mode can't handle this number, but it's pretty obvious that all the trailing 0's are wrong. Actual result: -------------- Here is the output text: 1Hash is '9789A9C80C9BFB6B40AD83670F14D64A' 2Hash is '9789A9C80C9BFB6B40AD83670F14D64A' 3Hash is '201428215609899446868600620602402480202' 4Hash is '9789A9C80C9BF8000000000000000000' 5Hash is '9789A9C80C9BF8000000000000000000' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35874&edit=1

« previous php.doc (#969371431) next »