While looking over some code, I found a function that seems to do exactly what bin2hex does. I tested on large sets of randomly generated input and they were identical. What I would like to know is if anyone can see any difference between them. Or maybe someone can give me some information about the implementation of bin2hex.
Here is the function I was telling you about:
function strToHex($str){
$result='';
$map = array(
'0' => '00',
'1' => '01',
'2' => '02',
'3' => '03',
'4' => '04',
'5' => '05',
'6' => '06',
'7' => '07',
'8' => '08',
'9' => '09',
'a' => '0a',
'b' => '0b',
'c' => '0c',
'd' => '0d',
'e' => '0e',
'f' => '0f'
);
for ($i=0; $i < strlen($str); $i++){
$tmp = dechex(ord($str[$i]));
if(isset( $map[$tmp]))
$tmp = $map[$tmp];
$result .= $tmp;
}
return $result;
}
Thank you,
Alin
I do not know the implementation details in PHP, but you can take a look of this javascript function (from the php.js) it is the equivalent to PHP bin2hex but written in JS.
}
You can see the original code here
HTH!