Why is long2ip conversion important?
Frequently Asked Questions about Convert long to IP address https://long2ip.com/faq/
- What is long2ip conversion?
- Why is long2ip conversion important?
- Where is long2ip used?
- How to use long2ip conversion
Where is long2ip used?
Long2ip conversion is mainly used to swiftly look up an IP address without having to make time-consuming calculations to get there. IP addresses are often saved as long in databases because the server can perform queries more quickly, but this also means that they basically become almost unreadable for the human eye.
Why is long2ip conversion important?
IP addresses are often saved in databases as decimals, because it's easier for a database server to compare numbers with each other than to compare IP addresses. Because it's very difficult for people to be able to see or even imagine a long IP, we use long2ip converter tools to quickly look up an IP address.
What is long2ip conversion?
A long integer is a way of saving an IP address as a number in a database. A number is easier to use than an IP address in databases when making comparisons.
An IP address consists of 4 numbers that are divided by points, for example 8.8.8.8.
An IP address is "base 256", and to convert the IP address 8.8.8.8.to decimal (base 10) we use the following formula:
8 x (256)^3 + 8 x (256)^2 + 8 x (256)^1 + 8 (256)^0
package com.test.long2ip;
public class Long2ipConversion {
public Long getPow(int i) {
return (long) Math.pow(256, i);
}
public String long2ip(long long_) {
long i = long_;
short part3 = (short) (long_ % getPow(1));
i -= part3;
short part2 = (short) (i % getPow(2) / getPow(1));
i -= part2 * getPow(1);
short part1 = (short) (i % getPow(3) / getPow(2));
i -= part1 * getPow(2);
short part0 = (short) (i / getPow(3));
return part0 + "." + part1 + "." + part2 + "." + part3;
}
public String long2ip(String long_) {
long intPointIp = Long.parseLong(long_.trim());
return long2ip(intPointIp);
}
public long ip2long(String ip_) {
String[] ip_s = ip_.trim().split("\\.");
long res = 0;
short ii = 3;
for (String i : ip_s) {
res += Long.parseLong(i) * getPow(ii);
ii -= 1;
}
return res;
}
}
https://github.com/toywei/long2ip
Why is long2ip conversion important?的更多相关文章
- ADC and DAC Analog Filters for Data Conversion
Figure 3-7 shows a block diagram of a DSP system, as the sampling theorem dictates it should be. Bef ...
- Cannot perform conversion to XML from legacy HTML:
错误信息:Cannot perform conversion to XML from legacy HTML: The nekoHTML library is not in classpath. ne ...
- Base Conversion In PHP and javascript
http://www.exploringbinary.com/base-conversion-in-php-using-built-in-functions/ http://www.binarycon ...
- Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...
- View and Data API Tips : Conversion between DbId and node
By Daniel Du In View and Data client side API, The assets in the Autodesk Viewer have an object tree ...
- 【leetcode】ZigZag Conversion
题目简述 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...
- CSS中"!important"的使用
本篇文章使用最新的IE10以及firefox与chrome测试(截止2013年5月27日22:23:22) CSS的原理: 我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < ...
- Conversion Operators in OpenCascade
Conversion Operators in OpenCascade eryar@163.com Abstract. C++ lets us redefine the meaning of the ...
- No.006:ZigZag Conversion
问题: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...
随机推荐
- ios开发之--MJRefresh上拉加载的时候,tableview会向上偏移
1,出现这种情况的原因: 这个应该是UITableView最大的改变.我们知道在iOS8引入Self-Sizing之后,我们可以通过实现estimatedRowHeight相关的属性来展示动态的内容, ...
- Python easyGUI 文件浏览 显示文件内容
#提供一个文件浏览夹.让用户选择需要打开的文件,打开并显示文件内容: import easygui as g import os msg='浏览文件并打开' title='测试' default='D ...
- C语言的声明的优先级规则
C语言的声明的优先级规则如下: A 声明从它的名字开始读取,然后按照优先级顺序依次读取 B 优先级从高到低依次是: B.1 声明中被括号括起来的那一部分 B.2 后缀操作符[圆括号 ()表示这 ...
- Selenium 执行JavaScript
Selenium 可以直接模拟运行 JavaScript,使用 execute_script() 方法即可实现 from selenium import webdriver browser = web ...
- fastcgi协议之一:定义
参考 深入理解fastcgi协议以及在php中的实现 https://mengkang.net/668.html fastcgi协议规范内容 http://andylin02.iteye.com/bl ...
- Clock skewdetected. Your build may be incomplete.
解决方法: find . -type f | xargs -n touch make clean make
- 批量更改数据库表架构(生成sql后直接执行!)
批量更改数据库表架构(生成sql后直接执行!) use my_test; --当前数据库 ), ), ), @NewSql VARCHAR(max), @Index INT; SET @SchemaO ...
- 【jquery基础】 jquery.manifest用法:通过后台查询and添加到默认项
今天做一个东西 效果如下: 后台已经保存了006这个SN码,现在需要查到了这个人(杨小婷),然后作为默认值,展示到 manifest 里面 <script> $(document).rea ...
- UVALive - 3507 Keep the Customer Satisfied
题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单 思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我 ...
- Android JNI与多线程
Java通过JNI调用本地C++代码是在同一个线程中的同步调用. JNI中如果新建的线程调用java的代码,那么java代码是运行在JNI线程中的:但是,如果调用UI相关的代码时需要与java主线程通 ...