Reputation: 2725
I have an sequence of 30 or so hexa decimal values 0x01, 0x02... My question is how can i store these values in Java. I do not know if it matters to convert it into String and store it. But thats what i am not looking for. I just want to store the hexa decimal as constant data. Please also consider the contents representing the Hex-Decimal form and if/what happens to it ?
Upvotes: 1
Views: 225
Reputation: 206846
Hexadecimal is just a format to display numbers, just like decimal, binary or octal. Numbers are just numbers - hexadecimal is not a property of the numbers themselves, it's only a way to display numbers.
Writing the numbers as 0x01
, 0x02
, etc. in your source code is exactly the same as writing them in decimal 1
, 2
etc.
So, you can store the numbers like you would store any other numbers - for example as an array of int
s.
Upvotes: 2
Reputation: 15367
Just store them in an integer (if it fits within the value range) ... when displaying them, convert it as hex.
Upvotes: 0
Reputation: 53829
You should store them as Integer
s using the Integer.valueOf(String s, int radix) method.
In your case, the radix is 16.
Upvotes: 2