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


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

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!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From Stanimir Stamenkov <s7an10@netscape.net>
Newsgroups comp.lang.java.programmer
Subject Re: convert byte array to hex string using BigInteger
Date Sat, 29 Jun 2013 19:10:20 +0300
Organization A noiseless patient Spider
Lines 32
Message-ID <kqn0j3$aj1$1@dont-email.me> (permalink)
References <kpur29$5v4$1@news.albasani.net> <51cb9f8f$0$32111$14726298@news.sunsite.dk>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Sat, 29 Jun 2013 16:04:51 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="f440b6fbb01220f6e5bcf0b7427f7582"; logging-data="10849"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oBk6Wrt3ie812lFGPaQnY"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 SeaMonkey/2.19
In-Reply-To <51cb9f8f$0$32111$14726298@news.sunsite.dk>
X-Face "@)%Vlap6d%OVYDS}B4YUWE@yUy+^!w/+.q.,c5kjI#+uG?kYP&r/pTjNWgo:g[A,O=AL3/ j&4Le2cau$<e=FPq~GbeZ6DW1Grey[VHn8?ktzvoQtzlg;]&rh8g]CD+_BC7d[gW{Yx&_X*4Q$h&nJ l@t(|4R4:T='&]U#ui+z9OC$.~gJjU93kh:Ojc$Cz0n#I9!~!9ay?E<UlW&5,IFX1*KtA>MYEFst$y y"m]M7tq\S(>[a$x0x8%S
Cancel-Lock sha1:n30ZYOI0iH4t9Pa6YS5ogX35GuY=
Xref csiph.com comp.lang.java.programmer:24541

Show key headers only | View raw


Wed, 26 Jun 2013 22:12:30 -0400, /Arne Vajhøj/:

> You have already received several working solutions.
>
> I will strongly recommend you drop the idea about using
> BigInteger for this.
>
> It becomes extremely tricky to get it right - you have already
> found the sign problem - next problem will be the leading zero
> problem.
>
> [... bunch of code...]

I may be dense, but I didn't got why using BigInteger is not good? 
What's wrong with the following, for example:

     byte[] val;
     ...
     String.format("%064x", new BigInteger(1, val));

I guess one could come up with a method like:

     String toHexString(byte[] val, int len) {
         BigInteger num = new BigInteger(1, val);
         return (len > 0) ? String.format("%0" + len + "x", num)
                          : String.format("%x", num);
     }

Doesn't it appear sufficient?

-- 
Stanimir

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