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 "1111111111111111111111110" is displayed because I used the function of php DECBIN that transforms decimal into binary. The problem is that by doing this, the eight bits of the last octet are not displayed, since the last number is "0" in decimal. Below is my code. Does anyone know of a way to transform 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];
}