Java Byte to Hex String byteToHexString(byte value)

Here you can find the source of byteToHexString(byte value)

Description

Converts the given byte into an hex string.

License

Mozilla Public License

Parameter

Parameter Description
value Byte to convert to hex string.

Return

Converted byte to hex string.

Declaration

public static String byteToHexString(byte value) 

Method Source Code

//package com.java2s;
/**/*from  w  ww. j av a2  s .co  m*/
 * Copyright (c) 2014-2016 Digi International Inc.,
 * All rights not expressly granted are reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 * =======================================================================
 */

public class Main {
    private static final String HEXES = "0123456789ABCDEF";

    /**
     * Converts the given byte into an hex string.
     * 
     * @param value Byte to convert to hex string.
     * 
     * @return Converted byte to hex string.
     */
    public static String byteToHexString(byte value) {
        final StringBuilder hex = new StringBuilder(2);
        byte b = value;
        hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
        return hex.toString();
    }
}

Related

  1. byteToHexString(byte ib)
  2. byteToHexString(byte in)
  3. byteToHexString(byte num)
  4. byteToHexString(byte src)
  5. byteToHexString(byte value)
  6. byteToHexString(byte[] b)
  7. byteToHexString(byte[] b)
  8. byteToHexString(byte[] bytes)
  9. byteToHexString(byte[] bytes, int start, int end)