From 476b21671357327a4b7ff174d08d0a8e513d651b Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 23 Aug 2017 16:21:47 +0900 Subject: [PATCH] added int to ip --- .../overflow/commons/utils/StringConvertor.java | 15 +++++++++++++++ .../commons/utils/StringConvertorTest.java | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/com/loafle/overflow/commons/utils/StringConvertor.java create mode 100644 src/test/java/com/loafle/overflow/commons/utils/StringConvertorTest.java diff --git a/src/main/java/com/loafle/overflow/commons/utils/StringConvertor.java b/src/main/java/com/loafle/overflow/commons/utils/StringConvertor.java new file mode 100644 index 0000000..42197f1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/commons/utils/StringConvertor.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.commons.utils; + +/** + * Created by snoop on 17. 8. 23. + */ +public class StringConvertor { + + public static String intToIp(long i) { + return ((i >> 24 ) & 0xFF) + "." + + ((i >> 16 ) & 0xFF) + "." + + ((i >> 8 ) & 0xFF) + "." + + ( i & 0xFF); + } + +} diff --git a/src/test/java/com/loafle/overflow/commons/utils/StringConvertorTest.java b/src/test/java/com/loafle/overflow/commons/utils/StringConvertorTest.java new file mode 100644 index 0000000..a159503 --- /dev/null +++ b/src/test/java/com/loafle/overflow/commons/utils/StringConvertorTest.java @@ -0,0 +1,17 @@ +package com.loafle.overflow.commons.utils; + +import org.junit.Test; + +/** + * Created by snoop on 17. 8. 23. + */ +public class StringConvertorTest { + @Test + public void intToIp() throws Exception { + + String ipStr = StringConvertor.intToIp(3232235797L); + + System.out.println(ipStr); + } + +} \ No newline at end of file