note 109169 added to function.hexdec
| From: | holdoffhunger at gmail dot com | Date: | Mon, 25 Jun 2012 18:29:43 +0000 |
| Subject: | note 109169 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188791@lists.php.net to get a copy of this message | ||
When given large numbers, the hexdec function automatically converts the value to scientific
notation. So, "aa1233123124121241" as a hexadecimal value will be converted to
"3.13725790445E+21". If you're converting a hexadecimal value that represents a hash
value (md5 or sha), then you need every single bit of that representation to make it useful. By
using the number_format function, you can do that perfectly. For example :
<?php
// Author: holdoffhunger@gmail.com
// Example Hexadecimal
// ---------------------------------------------
$hexadecimal_string = "1234567890abcdef1234567890abcdef";
// Converted to Decimal
// ---------------------------------------------
$decimal_result = hexdec($hexadecimal_string);
// Print Pre-Formatted Results
// ---------------------------------------------
print($decimal_result);
// Output Here: "2.41978572002E+37"
// .....................................
// Format Results to View Whole All Digits in Integer
// ---------------------------------------------
// ( Note: All fractional value of the
// Hexadecimal variable are ignored
// in the conversion. )
$current_hashing_algorithm_decimal_result = number_format($decimal_result, 0, '',
'');
// Print Formatted Results
// ---------------------------------------------
print($current_hashing_algorithm_decimal_result);
// Output Here: "24197857200151253041252346215207534592"
// .....................................
?>
----
Server IP: 69.147.83.197
Probable Submitter: 68.9.137.178
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- https://master.php.net/note/edit/109169
Del: integrated -- https://master.php.net/note/delete/109169/integrated
Del: useless -- https://master.php.net/note/delete/109169/useless
Del: bad code -- https://master.php.net/note/delete/109169/bad+code
Del: spam -- https://master.php.net/note/delete/109169/spam
Del: non-english -- https://master.php.net/note/delete/109169/non-english
Del: in docs -- https://master.php.net/note/delete/109169/in+docs
Del: other reasons-- https://master.php.net/note/delete/109169
Reject -- https://master.php.net/note/reject/109169
Search -- https://master.php.net/manage/user-notes.php