Java Hex Calculate toHex(byte b)

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

Description

to Hex

License

Open Source License

Declaration

private static String toHex(byte b) 

Method Source Code

//package com.java2s;
/*/*from   w w w .  j  a  v a  2 s .  c  om*/
 * Copyright ? 2008  Red Hat Middleware, LLC. or third-party contributors as indicated 
 * by the @author tags or express copyright attribution statements applied by the 
 * authors. All third-party contributions are distributed under license by Red Hat 
 * Middleware LLC.
 *
 * This copyrighted material is made available to anyone wishing to use, modify, copy, 
 * or redistribute it subject to the terms and conditions of the GNU Lesser General 
 * Public License, v. 2.1. This program is distributed in the hope that it will be 
 * useful, but WITHOUT A 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, 
 * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc., 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

public class Main {
    private static final char[] HEX_VALUES = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
            'b', 'c', 'd', 'e', 'f' };

    private static String toHex(byte b) {
        char[] characters = new char[2];
        characters[0] = HEX_VALUES[(b >>> 4) & 0x0F];
        characters[1] = HEX_VALUES[b & 0x0F];
        return new String(characters);
    }
}

Related

  1. toHex(boolean[] bits)
  2. toHex(byte b)
  3. toHex(byte b)
  4. tohex(byte b)
  5. toHex(byte b)
  6. toHex(byte b)