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 ...
随机推荐
- 使用gradle 编译生成 apk出现的问题
首先出现的问题是: Failed to read key from keystore 是我的Key Alias 填写错了, 还有一种可能就是真的把key放错位置了
- Spring集成Mybatis,spring4.x整合Mybatis3.x
Spring集成Mybatis,spring4.x整合Mybatis3.x ============================== 蕃薯耀 2018年3月14日 http://www.cnblo ...
- Explaining Delegates in C# - Part 1 (Callback and Multicast delegates)
I hear a lot of confusion around Delegates in C#, and today I am going to give it shot of explaining ...
- U3D功能脚本备忘
编译器属性 属性 介绍 用例 AddComponentMenu 在Component菜单中添加新的菜单项 [AddComponentMenu("Duan/Script/TestScript& ...
- 使用IDEA实现tomcat的热加载
1.打开tomcat的edit configuration,一定要选择war exploded 2.选择update classes and resources 3.配置基本就是这样,后面选择de ...
- Android学习之位图BitMap
BitMap代表一张位图,扩展名可以是.bmp或者.dib.位图是Windows标准格式图形文件,它将图像定义为由点(像素)组成,每个点可以由多种色彩表示,包括2.4.8.16.24和32位色彩.例如 ...
- x64枚举DPC定时器
@写在前面 不同于x86,x64的DPC是被加密了的.对于x64DPC的兴趣始于我已经流产的scalpel计划.当时问某牛怎么遍历,得到的答案是“500大洋给代码”.真是R了狗了,好歹小哥我 ...
- Esper学习之一:Esper介绍
CEP即Complex Event Process,中文意思就是“复杂事件处理”.听起来好像很复杂,实际上就是基于事件流进行数据处理,把要分析的数据抽象成事件,然后将数据发送到CEP引擎,引擎就会根据 ...
- Pry的安装
Pry 用于rails应用的调试 在Gemfile中添加 gem 'pry', :group =>:development bundle install 即可.pry代替irb方法,直接运行: ...
- 配置Groovy开发环境(Windows)
1.配置java环境 跳过具体配置 C:\Users\Administrator>java -version java version "1.8.0_45" Java(TM) ...