byte Array To Hex String : Hex « Date Type « Android

byte Array To Hex String

/* 2010-2011 mOcean Mobile. A subsidiary of Mojiva, Inc. All Rights Reserved.*/
//package com.adserver.adview;


public class Utils {

  public static String scrape(String resp, String start, String stop) {
    int offset, len;
    if((offset = resp.indexOf(start)) < 0)
      return "";
    if((len = resp.indexOf(stop, offset + start.length())) < 0)
      return "";
    return resp.substring(offset + start.length(), len);

  public static String md5(String data) {
    try {
      MessageDigest digester = MessageDigest.getInstance("MD5");
      byte[] messageDigest = digester.digest();
      return Utils.byteArrayToHexString(messageDigest);
    } catch(NoSuchAlgorithmException e) {      
    return null;
  public static String byteArrayToHexString(byte[] array) {
    StringBuffer hexString = new StringBuffer();
    for (byte b : array) {
      int intVal = b & 0xff;
      if (intVal < 0x10)
    return hexString.toString();    


Related examples in the same category

1.Hex Dump
2.converts given byte array to a hex string
3.converts given hex string to a byte array (ex: "0D0A" => {0x0D, 0x0A,})
4.Color name and its hex value
5.hex To Decimal
6.Get Hex string out of byte array
7.get Brightness, get Hex Name
8.String to Hex
9.Convenience method to convert a byte to a hex string.
10.Convenience method to convert a byte array to a hex string.
11.Convert a byte[] array to readable string format. This makes the "hex" readable!
12.Decode Unicode Hex