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


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

Re: convert byte array to hex string using BigInteger

X-Received by 10.236.118.194 with SMTP id l42mr10479783yhh.2.1385253832608; Sat, 23 Nov 2013 16:43:52 -0800 (PST)
X-Received by 10.49.35.107 with SMTP id g11mr242770qej.5.1385253832593; Sat, 23 Nov 2013 16:43:52 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!dz2no3620586qab.0!news-out.google.com!p7ni12qat.0!nntp.google.com!i2no3623460qav.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Sat, 23 Nov 2013 16:43:52 -0800 (PST)
In-Reply-To <kpur29$5v4$1@news.albasani.net>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=95.151.145.91; posting-account=lyDvJgoAAADE_z9-bIyiZsYzn47efUb7
NNTP-Posting-Host 95.151.145.91
References <kpur29$5v4$1@news.albasani.net>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <aaa71880-263c-422c-9b59-44b3520950db@googlegroups.com> (permalink)
Subject Re: convert byte array to hex string using BigInteger
From aydin.k.abadi@gmail.com
Injection-Date Sun, 24 Nov 2013 00:43:52 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.java.programmer:26592

Show key headers only | View raw


Hi
in c++ ,there is no val.length to check the size of val similar to Binint(byte [] val) in java, can anybody let me know,please,what exactly I need to do. 


Regards
Aydin


On Thursday, June 20, 2013 1:03:21 PM UTC+1, Laura Schmidt wrote:
> Hi,
> 
> 
> 
> I try to convert a byte array to a hex string like this:
> 
> 
> 
>   private static String hex_encode (byte [] val)
> 
>   {
> 
>    BigInteger b = new BigInteger(val);
> 
> 
> 
>    String t = b.toString(16);
> 
> 
> 
>    return (t);
> 
>   }
> 
> 
> 
> For a long byte array it returns a "negative" hex string, i. e. starting 
> 
> with a "-" sign.
> 
> 
> 
> But I want just the bytes in the array converted to hex representation, 
> 
> each one ranging from "00" to "FF". There should be no minus sign then.
> 
> 
> 
> Can you help?
> 
> Thanks!
> 
> 
> 
> 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