---
title: "JAVA 长整型转换为IP地址的方法"
author: "testcs_dn"
date: "2014-08-11T10:15:00Z"
tags: []
slug: "java-ip"
draft: false
lastmod: "2014-08-11T18:06:16Z"
id: 2102561
url: "https://testcs-dn.iteye.com/blog/2102561"
---

JAVA 长整型转换为IP地址的方法

代码如下：

```
	/**
	 * 整型解析为IP地址
	 * @param num
	 * @return
	 */
	public static String int2iP(Long num) 
	{
	    String str = null;
	    Long[] tt = new Long[4];
	    tt[0] = (num >>> 24) >>> 0;
	    tt[1] = ((num << 8) >>> 24) >>> 0;
	    tt[2] = (num << 16) >>> 24;
	    tt[3] = (num << 24) >>> 24;
	    str = (tt[0]) + "." + (tt[1]) + "." + (tt[2]) + "." + (tt[3]);
	    return str;
	}
```