forked from yeshodha02/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHexAsciiConvertor.java
More file actions
59 lines (54 loc) · 1.36 KB
/
HexAsciiConvertor.java
File metadata and controls
59 lines (54 loc) · 1.36 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.edurekademo.utilities;
public class HexAsciiConvertor {
/**
* Method to convert hexadecimal values into ascii
* method is return the ascii value
* @param hexValue
* @return outputAscii
*/
public static String convertHexToASCII(String hexValue)
{
StringBuilder outputAscii = new StringBuilder();
String asciiValue = null;
try{
if(hexValue!=null){
for (int i = 0; i < hexValue.length(); i += 2)
{
String str = hexValue.substring(i, i + 2);
outputAscii.append((char) Integer.parseInt(str, 16));
}
asciiValue = outputAscii.toString();
}
}
catch(Exception ex){
LoggerStackTraceUtil.printErrorMessage(ex);
}
return asciiValue;
}
/**
* Method to convert ascii values into hexadecimal
* method is returning the hexadecimal value
* @param asciiValue
* @return hex
*/
public static String convertAsciiToHex(String asciiValue)
{
String hexvalue = null;
try {
if(asciiValue!=null)
{
char[] chars = asciiValue.toCharArray();
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++)
{
hex.append(Integer.toHexString((int) chars[i]));
}
hexvalue= hex.toString();
}
}
catch (Exception e) {
LoggerStackTraceUtil.printErrorMessage(e);
}
return hexvalue;
}
}