Java Hex Calculate toHexString(byte[] b)

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

Description

translate byte array to Hex String .

License

Open Source License

Parameter

Parameter Description
b a parameter

Declaration

public static String toHexString(byte[] b) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w w  w.j ava 2s  .  c o m*/
     * translate byte array to Hex String .
     * 
     * @param b
     * @return
     */
    public static String toHexString(byte[] b) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < b.length; ++i) {
            buffer.append(toHexString(b[i]));
        }
        return buffer.toString();
    }

    /**
     * translate byte to hex String
     * 
     * @param b
     * @return
     */
    private static String toHexString(byte b) {
        char[] buffer = new char[2];
        buffer[0] = Character.forDigit((b >>> 4) & 0x0F, 16);
        buffer[1] = Character.forDigit(b & 0x0F, 16);
        return new String(buffer);
    }
}

Related

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