Android Byte Array to Hex Convert byte2hex(byte[] buffer, int len)

Here you can find the source of byte2hex(byte[] buffer, int len)

Description

bytehex

License

Open Source License

Declaration

public static String byte2hex(byte[] buffer, int len) 

Method Source Code

//package com.java2s;

public class Main {
    public static String byte2hex(byte[] buffer) {
        String h = "";

        for (int i = 0; i < buffer.length; i++) {
            String temp = Integer.toHexString(buffer[i] & 0xFF);
            if (temp.length() == 1) {
                temp = "0" + temp;
            }/*from   ww  w.j a v a  2  s.  c  o  m*/
            h = h + " " + temp;
        }

        return h;
    }

    public static String byte2hex(byte[] buffer, int len) {
        String h = "";

        for (int i = 0; i < len; i++) {
            String temp = Integer.toHexString(buffer[i] & 0xFF);
            if (temp.length() == 1) {
                temp = "0" + temp;
            }
            h = h + " " + temp;
        }

        return h;
    }

    public static String byte2hex(byte buffer) {
        String h = Integer.toHexString(buffer & 0xFF);
        if (h.length() == 1) {
            h = "0" + h;
        }
        return h;
    }
}

Related

  1. toHexadecimealString(byte[] data)
  2. bytesToHex(byte[] bytes)
  3. byte2hex(byte buffer)
  4. byte2hex(byte[] b)
  5. byte2hex(byte[] buffer)
  6. byte2hexWithoutSpace(byte[] buffer)
  7. byteArrayToHexString(byte[] b)
  8. byteArrayToHexString(final byte[] array)
  9. byteToHexString(Byte b)