-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertToHex.java
More file actions
23 lines (22 loc) · 874 Bytes
/
ConvertToHex.java
File metadata and controls
23 lines (22 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class ConvertToHex {
public static final char[] converter = {'a', 'b', 'c', 'd', 'e', 'f'};
public static String convertToHexMethod(String org) {
int[] asciis = new int[org.length()];
String out = "";
for (int i = 0; i<asciis.length; i++) {
int ascii_val = (int) org.charAt(i);
int onesdigit = ascii_val % 16;
int tensdigit = (ascii_val / 16) % 16;
if (tensdigit > 9) out += converter[tensdigit - 10];
else out += tensdigit;
if (onesdigit > 9) out += converter[onesdigit - 10];
else out += onesdigit;
out += " ";
//asciis[i] = ;
}
return out.substring(0, out.length() -1);
}
public static void main(String[] args) {
System.out.println(convertToHexMethod("i love C++ , not really"));
}
}