I have to convert an int to an hex value. This is for example the int value:
int_value = -13516;
To convert to a hex value i do:
hex_value = Integer.toHexString(int_value);
The value that I should get is : -34CC
(I don't know if i should make it positive).
The thing is that doing the conversion that way, the value that I get is: ffff cb34
Can't I use this function to make this conversion?
int_value = -13516; To convert to a hex value i do: hex_value = Integer.
toHexString() method in Java converts Integer to hex string. Let's say the following are our integer values. int val1 = 5; int val2 = 7; int val3 = 13; Convert the above int values to hex string.
Use the + Integer. toHexString() method in Java to convert integer to hexadecimal.
We call the toUpperCase() function on the resultant string, to get a hexadecimal value in uppercase. Alternatively, we can invoke the toHexString() function of the Integer class, which converts an integer to a hex string. Note that it performs the unsigned conversion and handles numbers less than or equal to Int.
Documentation says Integer.toHexString
returns the hexadecimal representation of the int
as an unsigned value.
I believe Integer.toString(value, 16)
will accomplish what you want.
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