convert hex to long  
Author Message
Jeff





PostPosted: 2005-12-21 4:39:00 Top

java-programmer, convert hex to long Hey

midp 2.0
J2ME Wireless Toolkit 2.2
JDK 5

Long id;
String arg1 = "0b"; //arg1 can also have values like "01", "0a" etc
id = Long.parseLong(arg1);

This converting isn't working with "0b" or "0a"... but I've read in the
documentation of jdk5 that this parseLong is overloaded:
public static long parseLong(String s, int radix), and I guess this is the
correct method to use, but I'm not sure what the second parameter (radix) of
this method is?

Jeff


 
Gordon Beaton





PostPosted: 2005-12-21 5:06:00 Top

java-programmer >> convert hex to long On Tue, 20 Dec 2005 21:39:04 +0100, Jeff wrote:
> Long id;
> String arg1 = "0b"; //arg1 can also have values like "01", "0a" etc
> id = Long.parseLong(arg1);
>
> This converting isn't working with "0b" or "0a"... but I've read in the
> documentation of jdk5 that this parseLong is overloaded:
> public static long parseLong(String s, int radix), and I guess this is the
> correct method to use, but I'm not sure what the second parameter (radix) of
> this method is?

"Radix" is another word for "base".

If your string contains a base 16 number, specify 16.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Oliver Wong





PostPosted: 2005-12-22 5:37:00 Top

java-programmer >> convert hex to long
"Gordon Beaton" <email***@***.com> wrote in message
news:43a87248$email***@***.com...
> On Tue, 20 Dec 2005 21:39:04 +0100, Jeff wrote:
>> Long id;
>> String arg1 = "0b"; //arg1 can also have values like "01", "0a" etc
>> id = Long.parseLong(arg1);
>>
>> This converting isn't working with "0b" or "0a"... but I've read in the
>> documentation of jdk5 that this parseLong is overloaded:
>> public static long parseLong(String s, int radix), and I guess this is
>> the
>> correct method to use, but I'm not sure what the second parameter (radix)
>> of
>> this method is?
>
> "Radix" is another word for "base".
>
> If your string contains a base 16 number, specify 16.

And in case that wasn't explicit enough, hexadecimal is base 16. Octal
is base 8. Binary is base 2. Decimal is base 10. Etc.

So for the OP's problem, yes, you want to use 16.

- Oliver