Remove duplicate file

This commit is contained in:
Grzegorz Piwowarek 2016-11-14 16:26:41 +01:00
parent 65c0aec94f
commit 315e1aa9cd
1 changed files with 0 additions and 46 deletions

View File

@ -1,46 +0,0 @@
package com.baeldung.hexToAscii;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HexToAscii {
@Test
public static void whenHexToAscii() {
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
assertEquals(asciiString, hexToAscii(hexEquivalent));
}
@Test
public static void whenAsciiToHex() {
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
assertEquals(hexEquivalent, asciiToHex(asciiString));
}
//
private static String asciiToHex(String asciiStr) {
char[] chars = asciiStr.toCharArray();
StringBuilder hex = new StringBuilder();
for (char ch : chars) {
hex.append(Integer.toHexString((int) ch));
}
return hex.toString();
}
private static String hexToAscii(String hexStr) {
StringBuilder output = new StringBuilder("");
for (int i = 0; i < hexStr.length(); i += 2) {
String str = hexStr.substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
return output.toString();
}
}