Long类型转换为IP String

package com.barry.iputil.util;

public class IPFormat {
    public static String toIPStr(Long LongIP) {
        if (LongIP <= 4_294_967_295L && LongIP >= 0L) {
            long item1 = LongIP & 0x000000FF;
            long item2 = LongIP >> 8 & 0x000000FF;
            long item3 = LongIP >> 16 & 0x000000FF;
            long item4 = LongIP >> 24 & 0x000000FF;
            return item4 +"." +item3 +"." +
                    item2 +"." +item1;
        }
        return "";
    }

    public static void main(String[] args) {

        System.out.println(IPFormat.toIPStr(3232278630L));
    }
}
posted @ 2022-03-03 12:38  KittySmith  阅读(60)  评论(0编辑  收藏  举报