I recently wanted to make a reversible conversion of decimal numbers to use as an invitation code. I have never figured out how to do it. It is too complicated. When I was working on IP today, I thought that this could be converted, so I studied the principle:
Mainly organized by myself:
$ip = '12.34.56.78'; $ips = explode('.', $ip); $result = 0; $result += $ips[0]<<24; $result += $ips[1]<<16; $result += $ips[2]<<8; $result += $ips[3]; echo bindec(decbin($result)); echo '<br>'; echo bindec(decbin(ip2long($ip))); echo '<br>'; $str = ''; $str .= intval($result/intval(pow(2, 24))) .'.'; $str .= intval(($result&0x00FFFFFF)/intval(pow(2, 16))) .'.'; $str .= intval(($result&0x0000FFFF)/intval(pow(2, 8))) .'.'; $str .= intval($result&0x000000FF); echo $str; echo '<br>'; echo long2ip($result);
203569230 203569230 12.34.56.78 12.34.56.78
This is just one way to achieve it, there are other ways
I wanted to use a similar method, which can directly convert a decimal number into other decimal values and reversibly, but I found too many problems when encountering values with many 0s in the middle, such as 1000100