I have noticed java will not allow me to store large numbers such as
2000000000, i.e 2 billion obviously to an integer type, but if I store the corresponding hex value i.e int largeHex = 0x77359400; this is fine,
So my program is going to need to increment up to 2^32, just over 4.2 billion, I tested out the hex key 0xffffffff and it allows me to store as type int in this form,
My problem is I have to pull a HEX string from the program.
Example
sT = "ffffffff";
int hexSt = Integer.valueOf(sT, 16).intValue();
this only works for smaller integer values
I get an error
Exception in thread "main" java.lang.NumberFormatException: For input string: "ffffffff"
All I need to do is have this value in an integer variable such as
int largeHex = 0xffffffff
which works fine?
I’m using integers because my program will need to generate many values.
Well, it seems there is nothing to add to the answers, but it’s worth it to clarify:
ffffffffis too big for an integer. ConsiderInteger.parseInt(""+Long.MAX_VALUE);, without using hex representation. The same exception is thrown here.int i = 0xffffffff;setsito-1.long l = 0xffffffff;will setlto-1as well, since0xffffffffis treated as an int. The correct form islong l = 0xffffffffL;.