Title: [Java] ipConversion.java Author: rylai Pastebin link: http://pastebin.com/VXr4nx0L First Edit: Friday 22nd of March 2013 05:45:11 PM CDT Last Edit: Friday 22nd of March 2013 05:45:11 PM CDT public class ipConversion {           /**          * @param args          */         public static void main(String[] args) {                 String[][] testCases = {                                                                 { "2002:c000:0204:0:0:0:0:0", "192.0.2.4" },                                                                 { "2002:c0a8:0101::", "192.168.1.1" },                                                                 { "2002:0808:0808::", "8.8.8.8" },                                                                 { "2002:92bf:5538::", "146.187.85.56" },                                                                 { "2001:0db8:85a3:0000:0000:8a2e:0370:7334",                                                                         "error" },                                                                 { "2002:0db8:85a3:0000:0000:8a2e:0370:7334",                                                                         "13.184.133.163" } };                 for (String[] s : testCases) {                         System.out.println("\n------------------------\n");                         System.out                                         .printf("[RESULT] * The input %s produced the output %s, expected %s\n",                                                         s[0], doIPConvert(s[0]), s[1]);                         System.out.println("\n------------------------\n");                 }         }           public static String doIPConvert(String source) {                 StringBuilder result = new StringBuilder();                 char[][] tempCharDoubleArray = new char[4][2];                 char[] tempCharArray;                 int[] tempIntArray = new int[4];                 if (!source.matches("^2002.*")) {                         return "error";                   }                   tempCharArray = source.split(":")[1].concat(source.split(":")[2])                                 .toLowerCase().toCharArray();                 for (int i = 0; i < tempCharArray.length; i += 2) {                         tempCharDoubleArray[i / 2] = new char[] { tempCharArray[i],                                                                                                                 tempCharArray[i + 1] };                 }                 System.out.printf("----[%s]----\n", source);                 for (int i = 0; i < 4; i++) {                         System.out.print(tempCharDoubleArray[i]);                         for (int j = 0; j < tempCharDoubleArray[i].length; j++) {                                 tempCharDoubleArray[i][j] = doCharHack(tempCharDoubleArray[i][j]);                         }                         System.out.println(" - " + ((byte) tempCharDoubleArray[i][0]) + " "                                         + (byte) tempCharDoubleArray[i][1]);                         tempIntArray[i] = ((byte) ((byte) (tempCharDoubleArray[i][0]) << 4) + ((byte) (tempCharDoubleArray[i][1]))) & 0xFF;                         System.out.println(tempIntArray[i]);                         result.append(tempIntArray[i]).append('.');                 }                 result.deleteCharAt(result.lastIndexOf("."));                 System.out.println("\n------------------------\n");                 return result.toString();         }           public static char doCharHack(char c) {                 if (c < 48)                         return c;                 c -= 48;                 if (c < 10)                         return c;                 c -= 39;                 return c;           }   }