Java Byte to Hex byteToHex(int v)

Here you can find the source of byteToHex(int v)

Description

Returns a two char hexadecimal String representation of a single byte.

License

Open Source License

Parameter

Parameter Description
v integer with a byte value (-128 .. 255); other values get truncated

Return

an absolute hex value representation (unsigned) of the input

Declaration

public static String byteToHex(int v) 

Method Source Code

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

public class Main {
    /** Returns a two char hexadecimal String representation of a single byte.
     * /*from  w  w w .  j a va 2 s.com*/
     * @param v integer with a byte value (-128 .. 255); other values get truncated
     * @return an absolute hex value representation (unsigned) of the input
     */
    public static String byteToHex(int v) {
        String hstr;
        hstr = Integer.toString(v & 0xff, 16);

        return hstr.length() == 1 ? "0" + hstr : hstr;
    }
}

Related

  1. byteToHex(final byte b)
  2. byteToHex(final byte b, StringBuilder buffer)
  3. byteToHex(final byte value)
  4. byteToHex(final byte value, final int minLength)
  5. byteToHex(final byte[] data)