note 73156 deleted from function.hexdec by bjori

From: Date: Sun, 11 Feb 2007 12:32:56 +0000
Subject: note 73156 deleted from function.hexdec by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123243@lists.php.net to get a copy of this message
Note Submitter: garmoan at gmail dot com ---- 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 ?>

« previous php.notes (#123243) next »