Search code examples
javahexzero

Java int to hex with 0x


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}; 

Solution

  • You could declare a String which will be equal to "0x" + Integer.toHexString(int)