Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to convert from BigInteger to Hex

881 views
Skip to first unread message

Nanaji

unread,
May 21, 2008, 10:20:32 PM5/21/08
to
I know we can convert from Integer.toHexString(int);

like wise how to convert BigInteger bi = new
BigInteger("4444444444444444444444444444");

How to convert bi to hex.


Regards
Nanaji

Arne Vajhøj

unread,
May 21, 2008, 10:35:41 PM5/21/08
to

Try:

bi.toString(16)

Arne

Nanaji

unread,
May 22, 2008, 6:42:53 AM5/22/08
to
Thanks, it works.

Regards
Nanaji

j1mb0jay

unread,
May 22, 2008, 7:29:13 AM5/22/08
to

Im sure you can pass a hex String into the constructor of BigInteger as
well. BigInteger bi = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFF",16);

Will the BigInteger Class go to any base ?

j1mb0jay.

Lew

unread,
May 22, 2008, 7:55:55 AM5/22/08
to
Please do not top-post.

Arne Vajhøj wrote:
>> bi.toString(16)

Nanaji wrote:
> Thanks, it works.

You should always look at the Javadocs first:
<http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html>

If you don't use the Javadocs (onscreen or memorized) for matters of the
standard API then you aren't really a Java programmer.

--
Lew

Lew

unread,
May 22, 2008, 7:59:03 AM5/22/08
to
Nanaji wrote:
>>> like wise how to convert BigInteger ... to hex.

Arne Vajhøj wrote:
>> Try:
>>
>> bi.toString(16)

j1mb0jay wrote:
> Im sure you can pass a hex String into the constructor of BigInteger as
> well. BigInteger bi = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFF",16);
>
> Will the BigInteger Class go to any base ?

You should always look at the Javadocs first:
<http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html#toString(int)>
<http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html#BigInteger(java.lang.String,%20int)>

Wojtek

unread,
May 22, 2008, 10:12:46 AM5/22/08
to
Lew wrote :

> If you don't use the Javadocs (onscreen or memorized) for matters of the
> standard API then you aren't really a Java programmer.

Memorized? I wish I had that kind of memory retention :-)

--
Wojtek :-)


Arne Vajhøj

unread,
May 22, 2008, 5:37:43 PM5/22/08
to
j1mb0jay wrote:
> On Wed, 21 May 2008 22:35:41 -0400, Arne Vajhøj wrote:
>> Nanaji wrote:
>>> I know we can convert from Integer.toHexString(int);
>>>
>>> like wise how to convert BigInteger bi = new
>>> BigInteger("4444444444444444444444444444");
>>>
>>> How to convert bi to hex.
>> Try:
>>
>> bi.toString(16)
>
> Im sure you can pass a hex String into the constructor of BigInteger as
> well. BigInteger bi = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFF",16);
>
> Will the BigInteger Class go to any base ?

That is the opposite direction.

Java Docs say:

Throws:
NumberFormatException - val is not a valid representation of a
BigInteger in the specified radix, or radix is outside the range from
Character.MIN_RADIX to Character.MAX_RADIX, inclusive.

which at least on my system means 2..36 !

Arne

Arne Vajhøj

unread,
May 22, 2008, 6:02:22 PM5/22/08
to
Lew wrote:
> If you don't use the Javadocs (onscreen or memorized) for matters of the
> standard API then you aren't really a Java programmer.

I don't think any programmer has memorized it all ...

Arne

Lew

unread,
May 22, 2008, 1:57:37 PM5/22/08
to
Please do not storm-post.

Arne Vajh??j wrote:
>> bi.toString(16)

Nanaji wrote:
> Thanks, it works.

You should therefore look at the Javadocs first:

If you don't possess the Javadocs (onscreen or learned) for matters of the
standard API then you aren't presently a Java killer.

--
Lew

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Sometimes the truth is so precious
it must be accompanied by a bodyguard of lies."

--- Offense Secretary Donald Rumsfeld

Lew

unread,
May 22, 2008, 8:29:08 PM5/22/08
to

Wow, you guys are so serious. I would not be surprised if there were one.

I just didn't want to insist that people use onscreen (or printed) Javadocs
and have someone object on the grounds that they had it memorized.

(And now Almond will do his oh-so-not-clever rewrite of my messages.)

--
Lew

0 new messages