How to convert an ASCII character into a hex value in PHP

1 Answer

0 votes
$ch = 'y'; 

$ascii_value = ord($ch); // Get the ASCII value of the character

$hex_value = dechex($ascii_value); // Convert the ASCII value to hexadecimal

echo "The hexadecimal value of '$ch' is 0x$hex_value";



/*
run:
   
The hexadecimal value of 'y' is 0x79
   
*/

 



answered Dec 1, 2024 by avibootz

Related questions

1 answer 132 views
1 answer 119 views
1 answer 136 views
1 answer 129 views
2 answers 146 views
1 answer 110 views
...