集册 Java实例教程 获取字节数组的主机地址

获取字节数组的主机地址

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

370
获取字节数组的主机地址


//package com.nowjava;
/* 来 自 n o w j a   v  a . c o m - 时  代  Java*/

public class Main {


    /**

     * 

     * @param bytes

     * @return host address,ex: 192.168.1.222

     */

    public static String getHostAddressOfBytes(byte[] bytes) {

        StringBuilder hostAddressBuilder = new StringBuilder();

        for (int i = bytes.length - 1; i >= 0; i--) {

            hostAddressBuilder.append("."

                    + Integer.toString(bytes[i] & 0xff));

        }

        return hostAddressBuilder.substring(1);

    }

}