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 139 views
1 answer 213 views
1 answer 88 views
1 answer 91 views
1 answer 115 views
1 answer 145 views
1 answer 93 views
93 views asked Dec 4, 2022 by avibootz
...