# how to convert from BigInteger to Hex

Discussion in 'Java' started by Nanaji, May 22, 2008.

1. ### NanajiGuest

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

Nanaji, May 22, 2008

2. ### Arne VajhøjGuest

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

Arne Vajhøj, May 22, 2008

3. ### NanajiGuest

Thanks, it works.

Regards
Nanaji
On May 22, 10:35 am, 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

Nanaji, May 22, 2008
4. ### j1mb0jayGuest

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.

j1mb0jay, May 22, 2008
5. ### WojtekGuest

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

Wojtek, May 22, 2008
6. ### Arne VajhÃ¸jGuest

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, May 22, 2008
7. ### Arne VajhÃ¸jGuest

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

Arne VajhÃ¸j, May 22, 2008