最近要做个十进制数字的可逆转换做邀请码,一直没搞清楚怎么弄的,实在太复杂了,今天弄IP时想到这个可以进行转换,于是研究了下原理:
主要是自己整理了下:
$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
这只是实现的一种方法而已,还有其他的办法
我是想用类似的方法,可以直接把一个十进制数字转换为其他十进制数值并可逆,但遇到中间有很多0的数值时发现问题太多了,如 1000100

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!