how to convert from BigInteger to Hex

N

Nanaji

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
 
A

Arne Vajhøj

Nanaji said:
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
 
J

j1mb0jay

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.
 
W

Wojtek

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 :)
 
A

Arne Vajhøj

j1mb0jay said:
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
 
A

Arne Vajhøj

Lew said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top