@Test public void testIPv4StringConversion() throws UnknownHostException { assertEquals("0.0.0.1", IPUtil.convertIPv4(1)); assertEquals("0.0.0.2", IPUtil.convertIPv4(2)); assertEquals("127.255.255.255", IPUtil.convertIPv4(Integer.MAX_VALUE)); assertEquals("128.0.0.0", IPUtil.convertIPv4(Integer.MIN_VALUE)); assertEquals("255.255.255.255", IPUtil.convertIPv4(-1)); assertEquals("223.255.255.0", IPUtil.convertIPv4((int) 3758096128l)); assertEquals("182.48.63.255", IPUtil.convertIPv4((int) 3056615423l)); }
public static String convertIPv4(final int ip) { int lastByteMask = 0b11111111; int i1 = ip >>> 24; int i2 = ip >> 16 & lastByteMask; int i3 = ip >> 8 & lastByteMask; int i4 = ip & lastByteMask; return String.format("%d.%d.%d.%d", i1, i2, i3, i4); }
IPUtil { public static String convertIPv4(final int ip) { int lastByteMask = 0b11111111; int i1 = ip >>> 24; int i2 = ip >> 16 & lastByteMask; int i3 = ip >> 8 & lastByteMask; int i4 = ip & lastByteMask; return String.format("%d.%d.%d.%d", i1, i2, i3, i4); } }
IPUtil { public static String convertIPv4(final int ip) { int lastByteMask = 0b11111111; int i1 = ip >>> 24; int i2 = ip >> 16 & lastByteMask; int i3 = ip >> 8 & lastByteMask; int i4 = ip & lastByteMask; return String.format("%d.%d.%d.%d", i1, i2, i3, i4); }  }
IPUtil { public static String convertIPv4(final int ip) { int lastByteMask = 0b11111111; int i1 = ip >>> 24; int i2 = ip >> 16 & lastByteMask; int i3 = ip >> 8 & lastByteMask; int i4 = ip & lastByteMask; return String.format("%d.%d.%d.%d", i1, i2, i3, i4); }  static String convertIPv4(final int ip); }
IPUtil { public static String convertIPv4(final int ip) { int lastByteMask = 0b11111111; int i1 = ip >>> 24; int i2 = ip >> 16 & lastByteMask; int i3 = ip >> 8 & lastByteMask; int i4 = ip & lastByteMask; return String.format("%d.%d.%d.%d", i1, i2, i3, i4); }  static String convertIPv4(final int ip);  }