Here you can find the source of toHexFromByte(final byte b)
Parameter | Description |
---|---|
b | byte the byte to be converted |
public static String toHexFromByte(final byte b)
//package com.java2s; //License from project: Open Source License public class Main { /** Allowable hex values */ private final static String[] hexSymbols = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; public final static int BITS_PER_HEX_DIGIT = 4; /**/* ww w.j a v a2 s .c o m*/ * Takes the given input and returns a String containing the hex representation of the byte. * * @param b * byte the byte to be converted * * @return String the hex conversion of the byte (2 characters) */ public static String toHexFromByte(final byte b) { // need to and the shift result as java maintains the // sign bit and puts it back after the shift byte leftSymbol = (byte) ((b >>> BITS_PER_HEX_DIGIT) & 0x0f); byte rightSymbol = (byte) (b & 0x0f); return (hexSymbols[leftSymbol] + hexSymbols[rightSymbol]); } }