this has been driving me nuts because i know theres a simple solution but i cant find it…
I have a edittext field that askes for an Hexadecimal number, the textfield is restricted to only receiving 0-9, a,b,c,d,e,f.
How do i convert this string to the actual number?
Example:
String = 0F => int = 0F or possibly => 0000 1111.
I’m trying to store MAC-addresses and then manipulating them and i only know how to store strings into SQLite! 🙂
Integer.parseInt(String s, int radix)is what you want. Pass in16as the radix. Read the docs here.For MAC addresses, you may find that
Integerisn’t a large enough type, so try theLongequivalent instead.And if even
Longisn’t big enough, or you want arbitrarily large precision, then useBigIntegerinstead. You can pass the radix to the constructor:public BigInteger(String val, int radix).And for even more flexibility, look at the
IntegerValidatorprovided by Apache Commons.