how to convert from BigInteger to Hex

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

  1. Nanaji

    Nanaji Guest

    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
    #1
    1. Advertising

  2. Nanaji

    Arne Vajhøj Guest

    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
    #2
    1. Advertising

  3. Nanaji

    Nanaji Guest

    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
    #3
  4. Nanaji

    j1mb0jay Guest

    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
    #4
  5. Nanaji

    Wojtek Guest

    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
    #5
  6. 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, May 22, 2008
    #6
  7. 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
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nick
    Replies:
    0
    Views:
    900
  2. nick
    Replies:
    1
    Views:
    31,785
    Eric Sosman
    Oct 26, 2004
  3. Replies:
    10
    Views:
    6,212
    Neredbojias
    Aug 19, 2005
  4. Bengt Richter
    Replies:
    6
    Views:
    471
    Juha Autero
    Aug 19, 2003
  5. Laura Schmidt
    Replies:
    21
    Views:
    695
    Andreas Leitgeb
    Nov 24, 2013
Loading...

Share This Page