Here you can find the source of byteToHexString(int nib1, int nib2)
Parameter | Description |
---|---|
nib1 | The first nibble of the byte. |
nib2 | The second nibble of the byte. |
public static String byteToHexString(int nib1, int nib2)
//package com.java2s; //License from project: Open Source License public class Main { /** /*from www . j av a 2 s. com*/ * Converts a single byte into a hexadecimal string. * * @param nib1 The first nibble of the byte. * @param nib2 The second nibble of the byte. * @return String representation of the hexadecimal representation of a byte. */ public static String byteToHexString(int nib1, int nib2) { char char1, char2; char[] chars = new char[2]; char1 = nibbleToChar(nib1); char2 = nibbleToChar(nib2); chars[0] = char2; chars[1] = char1; return (new String(chars)); } /** * Converts a nibble into a character. * * @param nibble The nibble. * @return A character representation of the hexadecimal nibble. */ public static char nibbleToChar(int nibble) { if (nibble < 10) { return (Integer.toString(nibble)).charAt(0); } else { int nib = nibble - 10; return (char) (((char) nib) + 'a'); } } }