I have a string as "5F2A" as Hex. I would like to convert it as int 0x5F2A.
String str = "5F2A";
int number = someOperation(str);
And the number should be (with 0x)
0x5F2A
Is it possible?
To rephrase and share what I learnt today
Map<Integer, String> map = new HashMap<>();
map.put(0x5F2A, "somevalue");
System.out.println(map.get(24362));
System.out.println(map.get(0b0101111100101010));
Would give the value somevalue for both.
System.out.println(number);will always output in decimal, not hexadecimal. You can useSystem.out.format.int i = 0x5F2A;int number = Integer.parseInt(str, 16);is transforming aStringto anintwith base 16(hex).0x5F2A.