Java Hex Calculate toHexString(byte[] bytes)

Here you can find the source of toHexString(byte[] bytes)

Description

byte array to base16

License

Open Source License

Parameter

Parameter Description
bytes input value

Return

hex representation of the byte array

Declaration

public static String toHexString(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final char[] base32 = "0123456789abcdefghijklmnopqrstuv".toCharArray();

    /**/*from  w ww  .  jav  a  2 s  .c o  m*/
     * byte array to base16
     *
     * @param bytes input value
     * @return hex representation of the byte array
     */
    public static String toHexString(byte[] bytes) {
        final char[] res = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int t = ((int) bytes[i]) & 0xFF;
            res[i * 2] = base32[(t >> 4) & 15];
            res[i * 2 + 1] = base32[t & 15];
        }
        return String.valueOf(res);
    }
}

Related

  1. toHexString(byte[] bytes)
  2. toHexString(byte[] bytes)
  3. toHexString(byte[] bytes)
  4. toHexString(byte[] bytes)
  5. toHexString(byte[] bytes)
  6. toHexString(byte[] bytes)
  7. toHexString(byte[] bytes)
  8. toHexString(byte[] bytes)
  9. toHexString(byte[] bytes)