ascii to decimal to hex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

ascii to decimal to hex

Post by mccommunity »

I am trying to conver a character to decimal then to hex, if I put in a l out of the word hello... the h and e work fine but the l should be 2a and it is coming back as only 2. Anyone know what is wrong? Thanks.

<?
$number = l;
$number = ord($number);
$number = $number - 66;
$number = dechex($number);


echo $number;
?>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Instead of your last line:
$number = dechex($number);

Try this:
$number = dechex($number*1);
Post Reply