Java Hex Calculate toHexPadZero(byte[] bytes)

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

Description

Convert bytes to hexadecimal representation.

License

Open Source License

Parameter

Parameter Description
bytes a parameter

Declaration

public static String toHexPadZero(byte[] bytes) 

Method Source Code

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

public class Main {
    private static final char[] hexChars = new char[] { '0', '1', '2', '3',
            '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    /**//from w  w w .  j a v a2  s. com
     * Convert bytes to hexadecimal representation.
     * Pad left with zeroes if necessary
     * @param bytes
     * @return
     */
    public static String toHexPadZero(byte[] bytes) {
        StringBuilder ret = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            ret.append(hexChars[(b >> 4) & 0xF]);
            ret.append(hexChars[b & 0xF]);
        }
        return ret.toString();
    }
}

Related

  1. toHexHashString(byte[] id)
  2. toHexLiteral(int v)
  3. toHexN(long src, int hexn)
  4. ToHexNumber(int c)
  5. toHexOrNegative(int i)
  6. toHexShortString(byte[] bytes)
  7. toHexStr(byte b[])
  8. toHexStr(byte[] b)
  9. toHexStr(byte[] binary)