I’ve been given the following PHP function and asked to write another function that reverses it.
function convertTo16bit($ipString) {
$ipString = explode(".", $ipString);
$ip = ($ipString[0] << 24) | ($ipString[1] << 16) | ($ipString[2] << 8) | ($ipString[3]);
$lowNumber = $ip & 0xffff;
$highNumber = ($ip >> 16) & 0xffff;
return array($lowNumber , $highNumber );
}
First Question: I understand what the above code is doing but not why, can someone explain why you would need to create a lowNumber and highNumber for example?
Secondly, I need to write a function called “convertToIPAddress” which takes an array similar to the one outputted above and return a string in the form of an IP address. Can anyone point me in the right direction?
Thanks
I figured it out…