Java Byte Array to Hex String bytesToHexString(byte[] bs)

Here you can find the source of bytesToHexString(byte[] bs)

Description

bytes To Hex String

License

Apache License

Declaration

public static String bytesToHexString(byte[] bs) 

Method Source Code

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

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

    public static String bytesToHexString(byte[] bs) {
        if (bs == null || bs.length == 0) {
            return "";
        }//from w  w w. j a  v  a  2 s  .  co  m
        StringBuffer str = new StringBuffer(bs.length * 4);
        for (int i = 0; i < bs.length; i++) {
            str.append(hex[(bs[i] >> 4) & 0x0f]);
            str.append(hex[bs[i] & 0x0f]);
        }
        return str.toString();
    }
}

Related

  1. bytesToHexString(byte[] array)
  2. bytesToHexString(byte[] b)
  3. bytesToHexString(byte[] b, int length)
  4. bytesToHexString(byte[] bArray)
  5. bytesToHexString(byte[] bArray)
  6. bytesToHexString(byte[] buf)
  7. bytesToHexString(byte[] byteArray)
  8. bytesToHexString(byte[] bytes)
  9. bytesToHexString(byte[] bytes)