Java Hex Calculate toHex(byte value)

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

Description

Returns a hexadecimal representation of the byte value.

License

Open Source License

Parameter

Parameter Description
value the value to convert

Return

the hexadecimal representation

Declaration

public static String toHex(byte value) 

Method Source Code

//package com.java2s;
/*/*from w  ww .j  a v  a  2 s .  c o  m*/
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /** hexadecimal digits. */
    public static final char HEX_DIGIT[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     * Returns a hexadecimal representation of the byte value.
     * <br><br>
     * Taken from <a href="http://www.herongyang.com/Cryptography/SHA1-Message-Digest-in-Java.html" target="_blank">here</a>.
     *
     * @param value   the value to convert
     * @return      the hexadecimal representation
     */
    public static String toHex(byte value) {
        StringBuilder result;

        result = new StringBuilder();
        result.append(HEX_DIGIT[(value >> 4) & 0x0f]);
        result.append(HEX_DIGIT[(value) & 0x0f]);

        return result.toString();
    }
}

Related

  1. toHex(byte in[])
  2. toHex(byte input[])
  3. toHex(byte lowByte)
  4. toHex(byte n)
  5. toHex(byte one)
  6. toHex(byte value)
  7. toHex(byte... bs)
  8. toHex(byte... bytes)
  9. toHex(byte[] a)