How to convert an integer to binary with leading zeros in PHP

1 Answer

0 votes
$a = 7;

echo sprintf("%04d", decbin($a)) . "\n";

echo sprintf("%08d", decbin(56)) . "\n";


  
  
  
/*
run:
   
0111
00111000
   
*/

 



answered Dec 27, 2021 by avibootz
...