I just tried to convert char into hex using the following code: <?php $char='H'; $format="------%02x----"; $hex=sprintf($format,$char); echo($hex); ?> Code (markup): this type of conversion works in C and Perl .. but its not working in php.. I just read in PHP.net 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
$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; ?> PHP: