zoukankan      html  css  js  c++  java
  • Why is long2ip conversion important?

    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



     
  • 相关阅读:
    第一阶段冲刺——4
    Day 1 测试流程--H模型
    【疑问】待解决
    Zookeeper 入门(一)
    【基础组件1】Flume入门(一)
    埋点测试、埋点接口测试
    单点登录 VS 多点登录
    web系统原理
    测试用例总结篇(一)
    功能测试心得(二)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10180332.html
Copyright © 2011-2022 走看看