Java Byte to Hex String byteToHexString(byte b)

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

Description

byte To Hex String

License

Open Source License

Parameter

Parameter Description
b a parameter

Return

byteToHexString

Declaration

public static String byteToHexString(byte b) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013, 2015 Orange./*from   w ww . ja  v a 2 s  .c  o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Victor PERRON, Antonin CHAZALET, Andre BOTTARO.
 *******************************************************************************/

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

    /**
     * @param b
     * @return byteToHexString
     */
    public static String byteToHexString(byte b) {
        char[] hexChar = new char[2];
        int v = b & 0xFF;
        hexChar[0] = hexArray[v >>> 4];
        hexChar[1] = hexArray[v & 0x0F];
        return new String(hexChar);
    }
}

Related

  1. byteToHexStr(byte src, int len, int code)
  2. byteToHexstr(byte[] b, boolean space)
  3. byteToHexStr(byte[] bArray)
  4. byteToHexString(byte _b)
  5. byteToHexString(byte b)
  6. byteToHexString(byte b)
  7. byteToHexString(byte b)
  8. byteToHexString(byte b)
  9. byteToHexString(byte b)