Here you can find the source of appendHexValue(final StringBuffer sb, final byte data)
Parameter | Description |
---|---|
sb | the StringBuffer. |
data | the data. |
static void appendHexValue(final StringBuffer sb, final byte data)
//package com.java2s; public class Main { /**/*from w w w .j ava 2s.c om*/ * Convert a byte into hex value and add to buffer. * * @param sb the StringBuffer. * @param data the data. */ static void appendHexValue(final StringBuffer sb, final byte data) { sb.append(nibbleToHex((byte) (data >> 4))); sb.append(nibbleToHex(data)); } /** * Convert lower 4 bits into a hex character. * * @param data the data byte * @return the hex character */ static char nibbleToHex(final byte data) { final int nibble = data & 0xf; if (nibble <= 9) { return (char) ('0' + nibble); } else { return (char) ('A' + nibble - 10); } } }