integer conversion
hi can any one tell me about any APIs for converting from hexadecimal value to a decimal value ieint a =0x23;now i want int b = decimal value of a is ther aby built in support to do this in java?
[223 byte] By [
hi_alla] at [2007-10-2 9:05:30]

> hi can any one tell me about any APIs for converting
> from hexadecimal value to a decimal value ie
> int a =0x23;
> now i want int b = decimal value of a
> is ther aby built in support to do this in java?
?
int b = a; // a is already in decimal...
System.out.println(a);
System.out.println(b);
Hi,Use this :b = Integer.parseInt(Integer.toHexString(a),16)Thanks
> Hi,
> Use this :
> b =
> Integer.parseInt(Integer.toHexString(a),16)[/u
> ]
> Thanks
No.
a is already an int.
int a = 0x10;
is identical to
int a = 16;
There's no conversion to be done, as prom already pointed out.
jverda at 2007-7-16 23:12:30 >

> Hi,> Use this :> b = Integer.parseInt(Integer.toHexString(a),16)> ThanksSo, in order to assign int b, you're converting int a into a String, and then parsing that String into an int... ?
sorry prom,JverdI just didnt think .. thanks..
> sorry prom,Jverd> I just didnt think .. thanks..No problem.; )
hey guysi am getting it as a String likeString s = "0x34";now i want the decimal value of 34I am doing some what like this is this correct? s = s.subString(2);nt decimalType = Integer.valueOf(s, 16);or any other "decent" way of doing it?
Take a look [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String, int)]here[/url].
> Take a look [url> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Inte> ger.html#parseInt(java.lang.String, int)]here[/url].No. This is NOT what the OP is looking for.
jverda at 2007-7-16 23:12:31 >

> > Take a look [url
> >
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Inte
>
> > ger.html#parseInt(java.lang.String,
> int)]here[/url].
>
>
> No. This is NOT what the OP is looking for.
Oops. Didn't read reply 7 closely enough. Nevermind.
jverda at 2007-7-16 23:12:31 >

> hey guys
> i am getting it as a String like
> String s = "0x34";
> now i want the decimal value of 34
Eh?
Typically "0x34" would mean it's a base-16 number, so the decimal value would be 52, not 34. Was that what you meant?
If so, then strip off the leading "0x" as you're doing and call parseInt, as ****_Adams suggests. That is, if you want an int. If you want an Integer, then use valueOf. Although I suppose autoboxing/unboxing will render the two equivalent here. I'd still use the one whose return type matches what you want to end up with though.
jverda at 2007-7-16 23:12:31 >

> doing and call parseInt, as ****_Adams suggests. ThatIs it just me, or is this .............^^^^^^^^^^^^^^..........a bit amusing?Sorry,Tim