Java Byte to Hex String byteToHexString(final byte inbyte)

Here you can find the source of byteToHexString(final byte inbyte)

Description

convert the given byte to Hex String

License

Open Source License

Parameter

Parameter Description
inbyte a parameter

Return

HexString

Declaration

public static String byteToHexString(final byte inbyte) 

Method Source Code

//package com.java2s;
/**/* ww w .j  ava2 s  . c  om*/
 *    Created on Oct 21, 2010
 *    This file is part of JObexFTP 2.0, and it contains parts of OBEX4J.
 *
 *    JObexFTP is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    JObexFTP is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with JObexFTP.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    /**
     * convert the given byte to Hex String
     *
     * @param inbyte
     * @return HexString
     */
    public static String byteToHexString(final byte inbyte) {
        String result = "0x";
        if (inbyte <= Byte.MAX_VALUE && inbyte >= 0) {
            if (inbyte < 16) {
                result += "0";
            }
            result += Integer.toHexString((int) inbyte);
        } else {
            result += Integer.toHexString(0x100 + inbyte);
        }
        return result;
    }
}

Related

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