Recently I want to make a reversible conversion of decimal numbers for the invitation code. I haven't figured out how to do it. It's too complicated. Today I think this can be converted when I get an IP address. So I studied the principle below:
I have sorted it out 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'
'; Echo bindec (decbin (ip2long ($ ip); echo'
'; $ 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'
'; Echo long2ip ($ result );
The output result is as follows:
20356923020356923012.34.56.7812.34.56.78
This is just one way to achieve it, and there are other ways
I want to use a similar method to convert a decimal number to another decimal value and convert it to reversible. However, when there are many numbers with 0 in the middle, I find that there are too many problems, such as 1000100.