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 274 views
1 answer 336 views
1 answer 221 views
1 answer 185 views
185 views asked Feb 14, 2025 by avibootz
1 answer 210 views
1 answer 246 views
1 answer 196 views
196 views asked Dec 4, 2022 by avibootz
...