Java Byte to Hex String byteToHexString(int b)

Here you can find the source of byteToHexString(int b)

Description

byte To Hex String

License

Academic Free License

Return

byte to two character hex string.

Declaration

public static String byteToHexString(int b) 

Method Source Code

//package com.java2s;
// Licensed under the Academic Free License version 3.0

public class Main {
    /**/*from   www. j a v  a 2 s .co  m*/
     * @return byte to two character hex string.
     */
    public static String byteToHexString(int b) {
        String s = Integer.toHexString(b & 0xFF);

        if (s.length() == 1)
            return "0" + s;
        else
            return s;
    }

    /**
     * Return hex string of bytes.
     */
    public static String toHexString(byte[] b) {
        StringBuffer s = new StringBuffer();
        for (int i = 0; i < b.length; ++i)
            s.append(byteToHexString(b[i]));
        return s.toString();
    }
}

Related

  1. byteToHexString(byte[] bytes, int start, int end)
  2. byteToHexString(byte[] data)
  3. byteToHexString(final byte b)
  4. byteToHexString(final byte b)
  5. byteToHexString(final byte inbyte)
  6. byteToHexString(int nib1, int nib2)
  7. byteToHexStringPadded(int value)
  8. byteToHexStringSingle(byte[] byteArray)