Convert a byte array to a Hex string : Convert to String « Data Type « Java






Convert a byte array to a Hex string

 
public class Main {

  public static void main(String[] argv) {
    byte[] b = "ada".getBytes();
   
    for (int i = 0; i < b.length; i++) {
      System.out.println(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
    }
    
  }
}
/*
61
64
61
*/

   
  








Related examples in the same category

1.Convert an int value to String: Integer.toString(i)
2.Use toString method of Integer class to conver Integer into String.
3.Convert an int value to String: new Integer(i).toString()
4.Convert an int value to String: concatenate string to an int value
5.Convert from integer to String
6.To catch illegal number conversion, try using the try/catch mechanism.
7.The Value of a String with String.valueOf method