What's the most efficient/elegant way to represent an MD5 in base 36?
Here's some code I've cribbed together from MD5 samples but this is
converting byte-by-byte to base 16 then on to base 36, which seems dumb.
But I'm kind of lost in all the different constructors and static
methods offered by Byte, String, Long, etc.
byte[] digest = md.digest();
StringBuffer hex = new StringBuffer();
for (byte b : digest) {
hex.append(Integer.toHexString(b & 0xff));
}
String base36 = new BigInteger(hex.toString(), 16).toString(36);
Thanks,
HT
Thomas Hawtin - 02 Jun 2006 18:00 GMT
> What's the most efficient/elegant way to represent an MD5 in base 36?
> Here's some code I've cribbed together from MD5 samples but this is
[quoted text clipped - 6 lines]
> for (byte b : digest) {
> hex.append(Integer.toHexString(b & 0xff));
^ This wont work for b between 0 and 15.
> }
> String base36 = new BigInteger(hex.toString(), 16).toString(36);
Can you not use the new BigInteger(int,byte[]) constructor?
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/