note 73156 added to function.hexdec
| From: | garmoan at gmail dot com | Date: | Sun, 11 Feb 2007 10:35:59 +0000 |
| Subject: | note 73156 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123237@lists.php.net to get a copy of this message | ||
Here's another hex to decimal converter... dunno if it'll be useful to anyone, but this
one just makes use of the BC functions so this thing will take any sized hex (as a string) and
return an any sized decimal number (as a string)
<?php
function bchexdec($hex) {
$hex = strtolower($hex);
$convert = '0';
$hexMap = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
'a' => 10, 'b' => 11, 'c' => 12,
'd' => 13, 'e' => 14, 'f' => 15);
for($i = 0; $i < strlen($hex); $i++) {
$hexPower = ((strlen($hex) - 1) - $i);
$curNum = bcmul($hexMap[$hex[$i]], (bcpow(16, $hexPower)));
$convert = bcadd($curNum, $convert);
}
return($convert);
}
?>
example:
<?php
echo bchexdec("6d4eb366b3b28e5f56cfe0b67d7607797f71e8816713aad4");
// prints 2680210260981918719218501443543552847839175168051723348692
?>
----
Server IP: 203.220.0.234
Probable Submitter: 60.229.9.38
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- https://master.php.net/note/edit/73156
Del: integrated -- https://master.php.net/note/delete/73156/integrated
Del: useless -- https://master.php.net/note/delete/73156/useless
Del: bad code -- https://master.php.net/note/delete/73156/bad+code
Del: spam -- https://master.php.net/note/delete/73156/spam
Del: non-english -- https://master.php.net/note/delete/73156/non-english
Del: in docs -- https://master.php.net/note/delete/73156/in+docs
Del: other reasons-- https://master.php.net/note/delete/73156
Reject -- https://master.php.net/note/reject/73156
Search -- https://master.php.net/manage/user-notes.php