i have a string of int value like "131008130225002" i need to convert it to hexadecimal string. I tried various ways,
- output of toHex function is 313331303038313330323235303032 but i do not need it,
i need in hexadecimal format using ABC upto 12 places.
I tried Integer.tohex, but it is out of range of integer
- In case of Double.tohex it gives 0x1.dc9ad4424da8p46
My friend is doing same job in ios using unsigned long long as datatype and 0x%02llx regular expression to convert nsstring
code is:
String x="131008130225002";
System.out.println(x);
// System.out.println(Integer.parseInt(x));
System.out.println(Double.parseDouble(x));
System.out.println(Double.toHexString(Double.parseDouble(x)));
String a1= toHex(x);
System.out.println(a1);
toHex function:
static String toHex(String arg) {
try {
return String.format("%12x", new BigInteger(1, arg.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}