Frequently Asked Questions about Convert long to IP address https://long2ip.com/faq/

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?的更多相关文章

  1. 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 ...

  2. Cannot perform conversion to XML from legacy HTML:

    错误信息:Cannot perform conversion to XML from legacy HTML: The nekoHTML library is not in classpath. ne ...

  3. Base Conversion In PHP and javascript

    http://www.exploringbinary.com/base-conversion-in-php-using-built-in-functions/ http://www.binarycon ...

  4. 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 ... 这个错误是因为有两个相 ...

  5. 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 ...

  6. 【leetcode】ZigZag Conversion

    题目简述 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows ...

  7. CSS中"!important"的使用

    本篇文章使用最新的IE10以及firefox与chrome测试(截止2013年5月27日22:23:22) CSS的原理: 我们知道,CSS写在不同的地方有不同的优先级, .css文件中的定义 < ...

  8. Conversion Operators in OpenCascade

    Conversion Operators in OpenCascade eryar@163.com Abstract. C++ lets us redefine the meaning of the ...

  9. No.006:ZigZag Conversion

    问题: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

随机推荐

  1. MyBatis入门程序之mapper映射文件常用配置命令

    1.ResultMap高级结果映射 如果查询出的列名和属性名不一致,可以通过ResultMap做映射,放在statement的输出类型中 如下: 2.动态SQL,使用各种动态标签实现动态拼接sql,常 ...

  2. 【代码审计】CLTPHP_v5.5.3 前台任意文件上传漏洞分析

      0x00 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chich ...

  3. httpClient创建对象、设置超时

    从老版本和新版本进行比较说明: 1.创建HttpClient对象 3.X: HttpClient httpClient = new DefaultHttpClient(); 4.3: Closeabl ...

  4. 脚本控制animation的事件

    由于动作设计经常修改动作,所以每次改完都要再添加一次animation的事件,所以就直接写了个脚本,当然以后可以做成表格,然后用脚本从表格中读取,然后生成对应的animation事件.在Assets/ ...

  5. [Ubuntu] 如何设置静态 IP 和 DNS

    编辑 /etc/network/interfaces 来设置 IP 和 DNS 解析服务器: # interfaces() ) and ifdown() auto lo iface lo inet l ...

  6. js中的假值

    undefined null 0 NaN 空字符串

  7. iOS - 栈顶VC控制器的获取

    iOS 获取当前顶层的ViewController #pragma mark - topVC - (UIViewController *)theTopviewControler { UIViewCon ...

  8. GNU Readline库函数的应用示例

    说明 GNU Readline是一个跨平台开源程序库,提供交互式的文本编辑功能.应用程序借助该库函数,允许用户编辑键入的命令行,并提供自动补全和命令历史等功能.Bash(Bourne Again Sh ...

  9. qcow2、raw、vmdk等镜像格式的比较和基本转换

    注:本文转自http://www.cnblogs.com/feisky/archive/2012/07/03/2575167.html   云计算用一个朋友的话来说:”做云计算最苦逼的就是得时时刻刻为 ...

  10. memcached stats 命令

    STAT pid 1552 STAT uptime 3792 STAT time 1262517674 STAT version 1.2.6 STAT pointer_size 32 STAT cur ...