Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24485

Re: convert byte array to hex string using BigInteger

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail
From Laura Schmidt <ls@mailinator.com>
Newsgroups comp.lang.java.programmer
Subject Re: convert byte array to hex string using BigInteger
Date Thu, 20 Jun 2013 15:32:56 +0200
Organization albasani.net
Lines 27
Message-ID <kpv0a9$gio$1@news.albasani.net> (permalink)
References <kpur29$5v4$1@news.albasani.net> <9hv5s85cul11v42sfop0388joag6mu6t4e@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net nNmLG4MIHWHG0DXLdQiI86nOobXHJ27SHSvEOGD3Ua5VZWhYhevYmabaJrGCnciswPOU7C+QtXLw8HENM6GTH/IYCmzwGUlfzTDg2dVnQhjumICDZyPe7yd6ine8/mq4
NNTP-Posting-Date Thu, 20 Jun 2013 13:32:57 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="P5O5efvJ+3TXkPitwJEiMLrAzEhkvfkVZ/le8Y7+N7uwR9L4aUj2+N8JdqhV0+3UJzpiMDpVRiepDaHPgl4Oa1pLR1aIO+nTkzduSTpNtj7cxRMwSIClAp3eERDdWusF"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130116 Icedove/10.0.12
In-Reply-To <9hv5s85cul11v42sfop0388joag6mu6t4e@4ax.com>
Cancel-Lock sha1:MokL3Cmd7+mQuEooH1sfDXcTByQ=
Xref csiph.com comp.lang.java.programmer:24485

Show key headers only | View raw


On 06/20/2013 03:09 PM, rossum wrote:

> This is a case of RTFM.  The Javadocs for BigInteger(byte[]) tell you
> that it expects the byte array in two's complement representation, so
> a leading 1 bit is interpreted as a negative number.  You need a
> different constructor:
>
>    public BigInteger(int signum, byte[] magnitude)

You are right, sorry.

Now I get a hex string without sign. But now the decode method does not 
return the original bytes anymore:

  private byte [] hex_decode (String val)
  {
   BigInteger b = new BigInteger (val,16);
   byte [] t = b.toByteArray();

   return (t);
  }

There is no other constructor for byte arrays.
And I don't really understand why it doesn't return the original byte array.

Laura

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

convert byte array to hex string using BigInteger Laura Schmidt <ls@mailinator.com> - 2013-06-20 14:03 +0200
  Re: convert byte array to hex string using BigInteger Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-06-20 09:03 -0400
  Re: convert byte array to hex string using BigInteger rossum <rossum48@coldmail.com> - 2013-06-20 14:09 +0100
    Re: convert byte array to hex string using BigInteger Laura Schmidt <ls@mailinator.com> - 2013-06-20 15:32 +0200
      Re: convert byte array to hex string using BigInteger rossum <rossum48@coldmail.com> - 2013-06-20 15:44 +0100
      Re: convert byte array to hex string using BigInteger lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-20 19:22 +0100
        Re: convert byte array to hex string using BigInteger markspace <markspace@nospam.nospam> - 2013-06-20 11:56 -0700
          Re: convert byte array to hex string using BigInteger lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-20 20:43 +0100
        Re: convert byte array to hex string using BigInteger Lew <lewbloch@gmail.com> - 2013-06-20 13:39 -0700
          Re: convert byte array to hex string using BigInteger lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-21 08:17 +0100
        Re: convert byte array to hex string using BigInteger Arne Vajhøj <arne@vajhoej.dk> - 2013-06-26 22:16 -0400
  Re: convert byte array to hex string using BigInteger Joerg Meier <joergmmeier@arcor.de> - 2013-06-20 22:09 +0200
  Re: convert byte array to hex string using BigInteger Roedy Green <see_website@mindprod.com.invalid> - 2013-06-21 14:51 -0700
    Re: convert byte array to hex string using BigInteger Joerg Meier <joergmmeier@arcor.de> - 2013-06-22 00:26 +0200
      Re: convert byte array to hex string using BigInteger Roedy Green <see_website@mindprod.com.invalid> - 2013-06-23 08:49 -0700
        Re: convert byte array to hex string using BigInteger Joerg Meier <joergmmeier@arcor.de> - 2013-06-23 22:37 +0200
      Re: convert byte array to hex string using BigInteger Roedy Green <see_website@mindprod.com.invalid> - 2013-06-23 12:40 -0700
        Re: convert byte array to hex string using BigInteger Joerg Meier <joergmmeier@arcor.de> - 2013-06-23 22:41 +0200
  Re: convert byte array to hex string using BigInteger Arne Vajhøj <arne@vajhoej.dk> - 2013-06-26 22:12 -0400
    Re: convert byte array to hex string using BigInteger Arne Vajhøj <arne@vajhoej.dk> - 2013-06-26 22:20 -0400
    Re: convert byte array to hex string using BigInteger Laura Schmidt <ls@mailinator.com> - 2013-06-28 07:55 +0200
      Re: convert byte array to hex string using BigInteger Joerg Meier <joergmmeier@arcor.de> - 2013-06-29 00:01 +0200
    Re: convert byte array to hex string using BigInteger Stanimir Stamenkov <s7an10@netscape.net> - 2013-06-29 19:10 +0300
      Re: convert byte array to hex string using BigInteger Arne Vajhøj <arne@vajhoej.dk> - 2013-07-03 22:24 -0400
  Re: convert byte array to hex string using BigInteger aydin.k.abadi@gmail.com - 2013-11-23 16:40 -0800
  Re: convert byte array to hex string using BigInteger aydin.k.abadi@gmail.com - 2013-11-23 16:43 -0800
    Re: convert byte array to hex string using BigInteger Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-24 10:43 +0000

csiph-web