集册 Java实例教程 将int ip值转换为点式ip地址格式

将int ip值转换为点式ip地址格式

欢马劈雪     最近更新时间:2020-01-02 10:19:05

547
将int ip值转换为点式ip地址格式
/** from 时 代      J a v a   公   众 号 - nowjava.com**/

/** 

 * Copyright 2012 InCNTRE, This file is released under Apache 2.0 license except for component libraries under different licenses

http://www.apache.org/licenses/LICENSE-2.0

 */


public class Main{


    /**

     * convert int ip value to dotted ip address format 

     * @param ipValue

     * @return

     */

    public static String toIPString(int ipValue) {


        FlowscaleController.logger.info("ip address is {}", ipValue);


        String a = Integer.toBinaryString(ipValue);

        String zeroString = "";

        for (int i = a.length(); i < 32; i++) {

            zeroString += "0";

        }

        a = zeroString + a;


        String ip = "";

        for (int i = 0; i < 4; i++) {


            ip = ip + "."
            /* 
 
展开阅读全文