Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android int to hex converting

Tags:

android

int

hex

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?

like image 731
masmic Avatar asked Aug 06 '13 10:08

masmic


People also ask

How to convert int to hex in Android?

int_value = -13516; To convert to a hex value i do: hex_value = Integer.

How to turn int into hex string?

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.

How to convert int to hex in Java?

Use the + Integer. toHexString() method in Java to convert integer to hexadecimal.

How to convert string to hexadecimal in Kotlin?

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.


1 Answers

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.

like image 62
arnefm Avatar answered Oct 06 '22 03:10

arnefm