Java Hex Calculate toHexString(byte[] buf, int offset, int len)

Here you can find the source of toHexString(byte[] buf, int offset, int len)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] buf, int offset, int len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

    public static String toHexString(byte[] buf, int offset, int len) {
        if (buf == null)
            return "null";
        StringBuilder b = new StringBuilder();
        for (int i = offset, j = 0; j < len && i < buf.length; i++, j++) {
            int idx0 = (buf[i] & 0xff) >> 4;
            int idx1 = buf[i] & 0xf;
            b.append(hexChars[idx0]);//from   w ww  .j a  v a  2  s  . c o m
            b.append(hexChars[idx1]);
        }
        return b.toString();
    }
}

Related

  1. toHexString(byte[] binary)
  2. toHexString(byte[] binaryData)
  3. toHexString(byte[] block)
  4. toHexString(byte[] buf)
  5. toHexString(byte[] buf)
  6. toHexString(byte[] buffer)
  7. toHexString(byte[] byteArray)
  8. toHexString(byte[] byteArray)
  9. toHexString(byte[] byteArray)