-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.java
37 lines (33 loc) · 885 Bytes
/
Converter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author root
*/
package Convert;
public class Converter
{
static String asciiToHex(String InputString)
{
char[] chars = InputString.toCharArray();
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++)
{
hex.append(Integer.toHexString((int) chars[i]));
}
return hex.toString();
}
static String hexToASCII(String HEXString)
{
StringBuilder output = new StringBuilder("");
for (int i = 0; i < HEXString.length(); i += 2)
{
String str = HEXString.substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
return output.toString();
}
}