Velocity Reviews > Java > how to convert from BigInteger to Hex

# how to convert from BigInteger to Hex

Nanaji
Guest
Posts: n/a

 05-22-2008
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
Guest
Posts: n/a

 05-22-2008
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)

Arne

Nanaji
Guest
Posts: n/a

 05-22-2008
Thanks, it works.

Regards
Nanaji
On May 22, 10:35*am, Arne Vajhøj <(E-Mail Removed)> 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)
>
> Arne

j1mb0jay
Guest
Posts: n/a

 05-22-2008
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)
>
> Arne

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.

Wojtek
Guest
Posts: n/a

 05-22-2008
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
Guest
Posts: n/a

 05-22-2008
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

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

Arne

Arne VajhÃ¸j
Guest
Posts: n/a

 05-22-2008
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