convert byte array to hex string using BigInteger

A

aydin.k.abadi

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
 
A

Andreas Leitgeb

Not sure, if I understand you correctly, but why use a BigInteger or even C++ at all?
The thread you replied to was quite long already, and I think there were a couple
of alternatives posted in it to do this rather simple task (byte[] -> hexstring)
in a loop, even without BigInteger.

Anyway, in C++ you would either pass the length of the array as a separate
argument, or create a wrapper class that packs pointer and length into one
entity (thus, mimicking Java).


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


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
 

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

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top