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 272 views
1 answer 334 views
1 answer 217 views
1 answer 180 views
180 views asked Feb 14, 2025 by avibootz
1 answer 208 views
1 answer 242 views
1 answer 191 views
191 views asked Dec 4, 2022 by avibootz
...