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. swift--歌曲播放示例

    使用MPMoviePlayerController我们可以是进行音乐播放,如下图: 接口的话,我是自己在本地上搭建了个服务器,自己请求自己

  2. hbase2.0.0-安装部署

    依赖hadoop 环境,我这边的版本是hadoop-2.6.5 选择hbase2.0.0版本的时候,去官网查看支持的hadoop版本 1.伪分布式安装 下载:http://mirror.bit.edu ...

  3. 【代码审计】iCMS_v7.0.7 search.admincp.php页面存在SQL注入漏洞

      0x00 环境准备 iCMS官网:https://www.icmsdev.com 网站源码版本:iCMS-v7.0.7 程序源码下载:https://www.icmsdev.com/downloa ...

  4. 数字图像处理笔记与体会(一)——matlab编程基础

    最近开始学习数字图像处理,使用matlab实现,下面我就来记录笔记和体会,一方面是给大家提供参考,另一方面是防止我忘记了. 复习一下: 1.数字图像是用一个数字矩阵来表示的,数字阵列中的每个数字,表示 ...

  5. 在iOS中使用icon font

    博文转载至 http://www.cocoachina.com/industry/20131111/7327.html 在开发阿里数据iOS版客户端的时候,由于项目进度很紧,项目里的所有图标都是用最平 ...

  6. Twitter的SnowFlake分布式id生成算法

    二进制相关知识回顾 1.所有的数据都是以二进制的形式存储在硬盘上.对于一个字节的8位到底是什么类型 计算机是如何分辨的呢? 其实计算机并不负责判断数据类型,数据类型是程序告诉计算机该如何解释内存块. ...

  7. 【linux系列】配置免密登陆

    一.SSH无密码登录原理 此操作是为了搭建hadoop集群进行的操作 Master(NameNode|JobTracker)作为客户端,要实现无密码公钥认证,连接到服务器Salve(DataNode| ...

  8. POP3协议分析

    http://m.blog.csdn.net/bripengandre/article/details/2192111 POP3协议分析 第1章.     POP3概述 POP3全称为Post Off ...

  9. linux下抓包学习--tcpdump的使用

    一.为什么需要学这个 很多时候,开发环境上不会出现问题.但在测试或者现场时,总是会有很多莫名其妙的问题. 这时候,能在出问题的环境上,开启抓包,然后再去重现问题的话,这时候,就可以拿到第一手的资料了. ...

  10. 用ChrootDirectory限制SFTP登录的用户只能访问指定目录且不能进行ssh登录

    创建不能ssh登录的用户sftpuser1,密码用于sftp登录: sudo adduser sftpuser1 --home /sftp/sftpuser1 --shell /bin/false s ...