A 16-byte array can be obtained through MessageDigest:
MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] digest = md5.digest(str);
Then traverse the byte array and convert each byte to hexadecimal
char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f' };
for (int x = 0; x < digest.length; x++) { sbr.append(hex[ digest[x] >> 4 & 0x0f] ) // take the high 4-bit decimal value (representing hexadecimal)
.append(hex[digest[x] & 0x0f); // take lower 4 bits
}
For example: byte i = 44;
convert binary to 0010 1100
0010 1100 >> 4 = 0010 // take the upper 4 digits
then 0000 0010 & 0000 1111 = 0000 0010 // convert to hexadecimal - 2
0010 1100 & 0000 1111 = 0000 1100 // Direct & is the lower 4 bits, because the upper 4 bits of 0xf are 0, then the result of the & & is also 0. Finally, convert to hexadecimal - c (decimal represents the number 12)
Finally, the result is 0x2c