I'm trying to convert int to hex with format 0x12 0x2B and so on. Is there anything similar like python: https://docs.python.org/2/library/functions.html#hex to accomplish this or i will need to work around this with many unnecessary steps?
I need to get something like this below:
int []hexInt={0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01};
You could declare a String which will be equal to "0x" + Integer.toHexString(int)
public static String intToHexStr(int i){
return "0x"+String.format("%2s", Integer.toHexString(i)).replace(' ', '0');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With