Here you can find the source of byteToHex(byte b)
Parameter | Description |
---|---|
b | The byte to process. |
static public String byteToHex(byte b)
//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); } }