Here you can find the source of appendHexValue(StringBuffer buffer, byte b)
Parameter | Description |
---|---|
b | byte Byte to convert |
public static void appendHexValue(StringBuffer buffer, byte b)
//package com.java2s; public class Main { /**//from ww w . j a v a2 s . c o m Helper method that converts a single byte to a hex string representation. @param b byte Byte to convert @return StringBuffer with the two-digit hex string */ public static void appendHexValue(StringBuffer buffer, byte b) { int[] digits = { (b >>> 4) & 0x0F, b & 0x0F }; for (int d = 0; d < digits.length; ++d) { int increment = (int) ((digits[d] < 10) ? '0' : ('a' - 10)); buffer.append((char) (digits[d] + increment)); } } /** Helper that appends a hex representation of a byte array to an existing StringBuffer. */ public static void appendHexValue(StringBuffer buffer, byte[] bytes) { for (int i = 0; i < bytes.length; ++i) appendHexValue(buffer, bytes[i]); } }