0
I’m developing an IP calculator in PHP. The problem is that when a mask is typed in decimal, example "255.255.255.0" the mask in binary is displayed " The problem is that doing so, the eight bits of the last Octeto are not displayed, as the last number is "0" in decimal. Below is my code. Does anyone know a way to turn with 32 bits?
$mascara_decimal = array("", "", "", "");
$mascara_decimal = explode(".", $_POST["mascara"]);
$mascara_binario = array("", "", "", "");
echo "Máscara em decimal: ";
echo $_POST["mascara"];
echo"<br>";
echo "Máscara em binário: ";
for ($i = 0; $i < 4; $i++) {
$mascara_binario[$i] = decbin($mascara_decimal[$i]);
echo $mascara_binario[$i];
}