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 284 views
1 answer 207 views
1 answer 248 views
1 answer 215 views
1 answer 205 views
1 answer 137 views
1 answer 180 views
...