Returns the hexadecimal value of the supplied byte array : Hexadecimal « Data Type « Java

Returns the hexadecimal value of the supplied byte array


 * Copyright Aduna ( (c) 1997-2006.
 * Licensed under the Aduna BSD-style license.

public class Utils {

   * Returns the hexadecimal value of the supplied byte array. The resulting
   * string always uses two hexadecimals per byte. As a result, the length
   * of the resulting string is guaranteed to be twice the length of the
   * supplied byte array.
  public static String toHexString(byte[] array) {
    StringBuilder sb = new StringBuilder(2*array.length);

    for (int i = 0; i < array.length; i++) {
      String hex = Integer.toHexString(array[i] & 0xff);

      if (hex.length() == 1) {


    return sb.toString();



Related examples in the same category

1.Convert Decimal to Hexadecimal
2.Convert from decimal to hexadecimal
3.Convert from Byte array to hexadecimal string
4.Convert from decimal to hexadecimal with leading zeroes and uppercase
5.Hex encoder and decoder.
6.Decode hex string to a byte array
7.Convert byte array to Hex String
8.Convert the bytes to a hex string representation of the bytes
9.Hex decimal dump
10.hex decoder
11.Get Base64 From HEX
12.Converts a hex string to a byte array.
13.append hex digit
14.dump an array of bytes in hex form
15.Get byte array from hex string
16.Check if the current character is an Hex Char <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66]
17.Helper function that returns a char from an hex
18.Hex encoder/decoder implementation borrowed from BouncyCastle
19.Java Hex dump Library
20.Util for digesting and encoding bytes/strings.
21.Provide hex utility for converting bytes to hex string
22.Number in hexadecimal format are used throughout Freenet.
23.Convert to/from Hex string
24.This class allows a number to be easily formatted as a hexadecimal number. The representation uses 0-f.
25.This class provides methods for working with hexadecimal representations of data.
26.Hex Util