Java Hex Calculate toHexString(byte b)

Here you can find the source of toHexString(byte b)

Description

to Hex String

License

Creative Commons License

Declaration

public static String toHexString(byte b) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

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

    public static String toHexString(byte b) {
        return toHexString(new byte[] { b });
    }/*w  ww  .j a v  a  2 s .  co m*/

    public static String toHexString(byte[] bytes) {
        return toHexString(bytes, false);
    }

    public static String toHexString(byte[] bytes, boolean spaced) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            int temp = b & 0xFF;
            sb.append(hexChars[temp >>> 4]);
            sb.append(hexChars[temp & 0xF]);
            if (spaced)
                sb.append(' ');
        }
        return sb.toString();
    }
}

Related

  1. toHexString(byte b)
  2. toHexString(byte b)
  3. toHexString(byte b)
  4. toHexString(byte b)
  5. toHexString(byte b)
  6. toHexString(byte b)
  7. toHexString(byte b)
  8. toHexString(byte b)
  9. toHexString(byte b)