Java Hex Calculate toHex(byte[] raw)

Here you can find the source of toHex(byte[] raw)

Description

to Hex

License

Apache License

Declaration

private static String toHex(byte[] raw) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static final char[] HEXES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
            'F' };

    private static String toHex(byte[] raw) {
        if (raw.length != 16)
            throw new IllegalArgumentException("length must be 16, not " + raw.length);
        final char[] hex = new char[32];
        short i = 0;
        for (final byte b : raw) {
            hex[i] = HEXES[(b & 0xF0) >> 4];
            hex[i + 1] = HEXES[(b & 0x0F)];
            i += 2;/* w ww.j a v  a  2  s. c  o  m*/
        }
        return new String(hex);
    }
}

Related

  1. toHex(byte[] inBytes)
  2. toHex(byte[] input)
  3. toHex(byte[] key)
  4. toHex(byte[] raw)
  5. toHex(byte[] raw)
  6. ToHex(byte[] src)
  7. toHex(byte[] src)
  8. toHex(byte[] text)
  9. toHex(byte[] v)