note 73244 deleted from function.base-convert by danbrown

From: Date: Sat, 02 Jul 2011 01:46:37 +0000
Subject: note 73244 deleted from function.base-convert by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181157@lists.php.net to get a copy of this message
Note Submitter: CFK ---- Here is the function made by David Leppek who works in both way : <?php function big_convert ($number,$to_base) { $result = ""; switch ($to_base) { case "2": $temp = preg_split('//', $number, -1, PREG_SPLIT_DELIM_CAPTURE); $lng = strlen($number); for ($i = 1;$i <= $lng;$i++) { $result .= str_pad(base_convert($temp[$i], 16, 2), 4, '0', STR_PAD_LEFT); } return $result; break; case "16": $bin = substr(chunk_split (strrev($number), 4,'-'), 0, -1); $temp = preg_split('[-]', $bin, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = count($temp)-1;$i >= 0;$i--) { $result = $result . base_convert(strrev($temp[$i]), 2, 16); } return strtoupper($result); break; } } $bin = "1011010011110010100100101011011101100101001101001111"; echo $hex = big_convert ($bin,16); echo big_convert ($hex,2); ?>

« previous php.notes (#181157) next »