Hey I have a String
containing 0xff906000
. Of course, it is way too big to be stored as an dec int. Instead I want the int look exactly as 0xff906000
- keeping it in hex format.
I can declare an int foo = 0xffffffff;
(not exceeding the int range) so there has to be a way to get my String
to my int while keeping the exact numbers.
I need all that for setBackgroundColor(int);
. I could enter the value as a decimal int but I want to keep the aRGB structure which is only possible via hex illustration (0xaaRRGGBB).
Integer.parseInt
throws java.lang.NumberFormatException: Invalid int: "0xff906000"
Integer.decode
is 'fully' converting the number exceeding the range of int
What are the other possibilities?
Elliott Frisch :
A computer will store the number in binary. Not hex, and not decimal. And an int cannot hold a value outside its' range - for that you'd need a long. For display purposes you can call Long.toHexString(long) like\n\nlong foo = 0xff90600000L;\nSystem.out.println(\"0x\" + Long.toHexString(foo));\n\n\nOutput is\n\n0xff90600000\n\n\nEdit For your updated value, use Integer.toHexString(int)\n\nint foo = 0xff906000;\nSystem.out.println(\"0x\" + Integer.toHexString(foo));\n\n\nOutput is\n\n0xff906000\n",
2014-10-15T13:08:04