Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

represent MD5 as a number in base36

Thread view: 
Henry Townsend - 02 Jun 2006 17:34 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
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.