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 160 views
1 answer 238 views
1 answer 105 views
1 answer 102 views
102 views asked Feb 14, 2025 by avibootz
1 answer 131 views
1 answer 164 views
1 answer 106 views
106 views asked Dec 4, 2022 by avibootz
...