Java Byte Array to Hex bytes2Hex(byte[] bts)

Here you can find the source of bytes2Hex(byte[] bts)

Description

bytes Hex

License

Apache License

Declaration

private static String bytes2Hex(byte[] bts) 

Method Source Code

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

public class Main {
    private static String bytes2Hex(byte[] bts) {
        String des = "";
        String tmp = null;//from w w w. j a v  a 2  s .  c  o  m
        for (int i = 0; i < bts.length; i++) {
            tmp = Integer.toHexString(bts[i] & 0xFF);
            if (tmp.length() == 1) {
                des = des + "0";
            }
            des = des + tmp;
        }
        return des;
    }

    private static String toHexString(byte[] ba) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < ba.length; i++) {
            str.append(String.format("%x", new Object[] { Byte.valueOf(ba[i]) }));
        }
        return str.toString();
    }
}

Related

  1. bytes2Hex(byte bt)
  2. bytes2Hex(byte... values)
  3. bytes2Hex(byte[] abValue)
  4. bytes2Hex(byte[] b)
  5. bytes2Hex(byte[] b)
  6. bytes2Hex(byte[] bts)
  7. bytes2Hex(byte[] byteArray)
  8. bytes2Hex(byte[] bytes)
  9. bytes2Hex(byte[] bytes)