How to convert binary to hex with leading zeros in PHP

1 Answer

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

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



  
  
  
/*
run:
   
0007
00b8
   
*/

 



answered Dec 27, 2021 by avibootz

Related questions

2 answers 300 views
1 answer 219 views
1 answer 257 views
1 answer 226 views
1 answer 218 views
1 answer 143 views
1 answer 194 views
...