Java Hex Calculate toHexString(byte[] in)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] in) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toHexString(byte[] in) {
        byte ch = 0x00;
        int i = 0;

        if (in == null || in.length <= 0)
            return null;

        String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };

        StringBuffer out = new StringBuffer(in.length * 2);

        while (i < in.length) {
            ch = (byte) (in[i] & 0xF0);
            ch = (byte) (ch >>> 4);
            ch = (byte) (ch & 0x0F);
            out.append(pseudo[(int) ch]);
            ch = (byte) (in[i] & 0x0F);
            out.append(pseudo[(int) ch]);
            i++;//from w  w  w.j  av a 2  s.  c  o  m
        }

        String rslt = new String(out);
        return rslt;

    }
}

Related

  1. toHexString(byte[] data, int start, int length)
  2. toHexString(byte[] digest)
  3. toHexString(byte[] digest)
  4. toHexString(byte[] digest)
  5. toHexString(byte[] digestByte)
  6. toHexString(byte[] input)
  7. toHexString(byte[] md)
  8. toHexString(byte[] messagePayload)
  9. toHexString(byte[] paramArrayOfByte)