Discount Perfume - Kamala Harris - Debt Consolidation - Wordpress Theme - Debt Consolidation

PDA

View Full Version : char to hex conversion problem????


nwk
Sep 18th 2007, 11:42 am
I just tried to convert char into hex using the following code:

<?php
$char='H';
$format="------%02x----";
$hex=sprintf($format,$char);
echo($hex);
?>


this type of conversion works in C and Perl .. but its not working in php.. I just read in PHP.net (http://in.php.net/manual/en/function.sprintf.php) about this and according to it, the code must work .. I don't understand the problem... Please let me know if you have any solution..

Thanks
Nwk

mariush
Sep 18th 2007, 3:05 pm
$char='H';
$asciicode = ord($char);
$hex = dechex($asciicode);
if (strlen($hex)!=2) $hex = '0'.$hex; // optional, adds 0 in front if needed
// add optional - signs here in front and back of $hex
echo $hex;
?>

nwk
Sep 22nd 2007, 9:15 am
You did it man....Thanks very much...lol