I have a single hexadecimal character, say
char c = 'A';
What's the proper way of converting that to its integer value
int value =??;
assert(a == 10);
Doesn't matter really for now if a is an int or a byte.
i don't see why you should have to convert to string... in fact this is what parseInt uses:
public static int digit(char ch, int radix)
int hv = Character.digit(c,16);
if(hv<0)
//do something else because it's not hex then.
int value;
try {
value = Integer.parseInt(Character.toString(c), 16);
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Not a hex char");
}
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