11package com .baeldung .hexToAscii ;
22
3+ import static org .junit .Assert .assertEquals ;
4+
5+ import org .junit .Test ;
6+
37public class HexToAscii {
48
59 @ Test
610 public static void whenHexToAscii () {
7-
811 String asciiString = "http://www.baeldung.com/jackson-serialize-dates" ;
912 String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573" ;
1013
@@ -13,15 +16,15 @@ public static void whenHexToAscii() {
1316
1417 @ Test
1518 public static void whenAsciiToHex () {
16-
1719 String asciiString = "http://www.baeldung.com/jackson-serialize-dates" ;
1820 String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573" ;
1921
2022 assertEquals (hexEquivalent , asciiToHex (asciiString ));
2123 }
2224
23- private static String asciiToHex ( String asciiStr ) {
25+ //
2426
27+ private static String asciiToHex (String asciiStr ) {
2528 char [] chars = asciiStr .toCharArray ();
2629 StringBuilder hex = new StringBuilder ();
2730 for (char ch : chars ) {
@@ -31,13 +34,13 @@ private static String asciiToHex(String asciiStr) {
3134 return hex .toString ();
3235 }
3336
34- private static String hexToASCII (String hexStr ) {
35-
37+ private static String hexToAscii (String hexStr ) {
3638 StringBuilder output = new StringBuilder ("" );
3739 for (int i = 0 ; i < hexStr .length (); i += 2 ) {
3840 String str = hexStr .substring (i , i + 2 );
3941 output .append ((char ) Integer .parseInt (str , 16 ));
4042 }
4143 return output .toString ();
4244 }
45+
4346}
0 commit comments