How to convert binary to hex in PHP

1 Answer

0 votes
$binary = '0111';
$hex = bindec($binary);
echo $hex . "\n";
echo sprintf('%04x', bindec($binary)) . "\n";

$binary = '10111000';
$hex = bindec($binary);
echo $hex . "\n";
echo sprintf('%04x', bindec($binary)). "\n";



  
  
  
/*
run:
   
7
0007
184
00b8
   
*/

 



answered Dec 27, 2021 by avibootz

Related questions

2 answers 273 views
1 answer 334 views
1 answer 219 views
1 answer 183 views
183 views asked Feb 14, 2025 by avibootz
1 answer 209 views
1 answer 244 views
1 answer 194 views
194 views asked Dec 4, 2022 by avibootz
...