Java Hex String Create appendHexByte(byte b, StringBuffer buf)

Here you can find the source of appendHexByte(byte b, StringBuffer buf)

Description

Append a byte in hexadecimal form, as two ASCII bytes, e.g.

License

Apache License

Parameter

Parameter Description
b the byte to write.
out the string buffer to write to.

Declaration

public static void appendHexByte(byte b, StringBuffer buf) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww .j  a v a  2  s. c  om*/
     * Append a byte in hexadecimal form, as two ASCII bytes, e.g. "5F" for 0x5F, to a StringBuffer.
     *
     * @param b the byte to write.
     * @param out the string buffer to write to.
     */
    public static void appendHexByte(byte b, StringBuffer buf) {
        // Write first char
        char c = (char) ((b >> 4) & 0xF);
        if (c > 9)
            c = (char) ((c - 10) + 'A');
        else
            c = (char) (c + '0');
        buf.append(c);

        // Write second char
        c = (char) (b & 0xF);
        if (c > 9)
            c = (char) ((c - 10) + 'A');
        else
            c = (char) (c + '0');
        buf.append(c);
    }
}

Related

  1. appendHex(StringBuffer stringbuffer, byte byte0)
  2. appendHex(StringBuilder bld, byte b)
  3. appendHex(StringBuilder buf, int value, int width)
  4. appendHex(StringBuilder buff, int i)
  5. appendHex(StringBuilder builder, int b)
  6. appendHexByte(final StringBuilder sb, final byte b)
  7. appendHexBytes(StringBuilder builder, byte[] bytes)
  8. appendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex)
  9. appendHexEntity(final StringBuilder out, final char value)