Java Hex Calculate toHexString(byte[] buf)

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

Description

http://homepage2.nifty.com/igat/igapyon/diary/2002/ig021213.html

License

Open Source License

Parameter

Parameter Description
buf a parameter

Return

Return Hex String Value.

Declaration

private static String toHexString(byte[] buf) 

Method Source Code

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

public class Main {
    /**// w  w w.  java2 s  . c  om
     * http://homepage2.nifty.com/igat/igapyon/diary/2002/ig021213.html
     * @param buf
     * @return Return Hex String Value.
     */
    private static String toHexString(byte[] buf) {
        String s = "";
        for (int i = 0; i < buf.length; i++) {
            int n = buf[i] & 0xff;
            if (n < 16) {
                s += " 0";
            } else {
                s += " ";
            }
            s += Integer.toHexString(n).toUpperCase();
        }
        return s;
    }
}

Related

  1. toHexString(byte[] ba, int offset, int length)
  2. toHexString(byte[] binary)
  3. toHexString(byte[] binaryData)
  4. toHexString(byte[] block)
  5. toHexString(byte[] buf)
  6. toHexString(byte[] buf, int offset, int len)
  7. toHexString(byte[] buffer)
  8. toHexString(byte[] byteArray)
  9. toHexString(byte[] byteArray)