I have the follow code:
$binary = \"110000000000\";
$hex = dechex(bindec($binary));
echo $hex;
?>
Which works fine, and I get a valu
You can prepend the requisite number of leading zeroes with something such as:
$hex = str_repeat("0", floor(strspn($binary, "0") / 4)).$hex;
What does this do?
strspn.floor to cast them out.str_repeat.Note that if the number of input bits is not a multiple of 4 this might result in one less zero hex digit than expected. If that is a possibility you will need to adjust accordingly.