Java Byte Array to Hex byteToHex(final byte b)

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

Description

byte To Hex

License

Open Source License

Declaration

private static String byteToHex(final byte b) 

Method Source Code

//package com.java2s;
/*//from  www.j  a v a  2 s.  c o m
 * Copyright Nathan Jones 2013
 *
 * This file is part of Juzidian.
 *
 * Juzidian 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.
 *
 * Juzidian 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 Juzidian.  If not, see <http://www.gnu.org/licenses/>.
 */

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

    private static String byteToHex(final byte b) {
        final char byteHexChar1 = HEX_CHARS[(b & 0xf0) >> 4];
        final char byteHexChar2 = HEX_CHARS[b & 0x0f];
        return byteHexChar1 + "" + byteHexChar2;
    }
}

Related

  1. byteToHex(byte[] buffer)
  2. ByteToHex(byte[] bytes)
  3. byteToHex(byte[] content, int nLength)
  4. byteToHex(byte[] raw)
  5. byteToHex(final byte b)
  6. bytetoHex(final byte data, final StringBuffer buffer)
  7. byteToHex(int val)
  8. byteToHex(int val, StringBuffer sb)
  9. byteToHexDisplayString(byte[] b)