Java Byte to Hex byteToHex(byte b)

Here you can find the source of byteToHex(byte b)

Description

Converts a byte to the string representation of its hex value.

License

Open Source License

Parameter

Parameter Description
b The byte to process.

Return

A string consisting of hex digits.

Declaration

static public String byteToHex(byte b) 

Method Source Code

//package com.java2s;
/*--------------------------------------------------------------------------------
 Copyright (C) 2002, 2004 ISOGEN International

 http://www.isogen.com/*  w w  w.  j av  a  2 s .com*/

 This program 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.

 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 Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 --------------------------------------------------------------------------------*/

public class Main {
    /**
     * Converts a byte to the string representation of its hex value. 
     * @param b The byte to process.
     * @return A string consisting of hex digits.
     */
    static public String byteToHex(byte b) {
        // Returns hex String representation of byte b
        char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
        return new String(array);
    }
}

Related

  1. bytesToPrettyHex(byte[] data)
  2. bytesToReadableHexStr(byte[] msg)
  3. bytesToUpperCaseHex(byte[] b)
  4. byteToHex(byte a)
  5. byteToHex(byte b)
  6. byteToHex(byte b)
  7. byteToHex(byte b)
  8. byteToHex(byte b)
  9. byteToHex(byte b)