Java Hex Calculate toHexString(byte b)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte b) 

Method Source Code

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

public class Main {

    public static String toHexString(byte b) {
        StringBuffer result = new StringBuffer(3);
        result.append(Integer.toString((b & 0xF0) >> 4, 16));
        result.append(Integer.toString(b & 0x0F, 16));
        return result.toString();
    }//ww  w.  j a  va2  s  .com

    public static String toHexString(byte[] bytes) {
        if (bytes == null) {
            return null;
        }

        StringBuffer result = new StringBuffer();
        for (byte b : bytes) {
            result.append(Integer.toString((b & 0xF0) >> 4, 16));
            result.append(Integer.toString(b & 0x0F, 16));
        }
        return result.toString();
    }

    public static String toHexString(byte[] bytes, int offset, int length) {
        if (bytes == null) {
            return null;
        }

        StringBuffer result = new StringBuffer();
        for (int i = offset; i < offset + length; i++) {
            result.append(Integer.toString((bytes[i] & 0xF0) >> 4, 16));
            result.append(Integer.toString(bytes[i] & 0x0F, 16));
        }
        return result.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[])