yf0994 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Bytes.toHex() #1143

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Convert byte arrays to their hexadecimal representation.

Case is specified.

Returns char[] to avoid initializing a String if unnecessary.

Original issue reported on code.google.com by pie...@spotify.com on 10 Sep 2012 at 2:48

Attachments:

GoogleCodeExporter commented 9 years ago
If this were to go in primitives, UnsignedBytes would probably be the correct 
place. Anyway, if support for hex encoding/decoding is added to Guava it'll be 
in the form of a more general binary encoding/decoding supporting hex, base64, 
etc.

Original comment by cgdecker@google.com on 10 Sep 2012 at 4:39

GoogleCodeExporter commented 9 years ago
I don't know how signedness plays a role here, but UnsignedBytes sounds fine 
anyway.

I'm going to do my Mr Obvious:

Base 16 is very commonly used for human-readable representation of binary data 
(including hashes). One of the nice properties is that each byte takes exactly 
two characters.  It's also really helpful to display hashes.

Base 64 is more complex and AFAICT mostly used for compact, machine-readable 
ASCII representation.

Not sure what would go into "etc." but I guess none of the other encodings 
would be nearly as commonly used, or straightforward to implement.

Original comment by pie...@spotify.com on 10 Sep 2012 at 5:07

GoogleCodeExporter commented 9 years ago
For hashes, the HashCode objects produced by our hashing package have a 
toString() that returns the hex form of the bytes. You can wrap a byte array as 
a HashCode directly using HashCodes.fromBytes(byte[]).

Original comment by cgdecker@google.com on 10 Sep 2012 at 7:07

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08