Java Hex String Create appendHexString(StringBuffer buffer, byte data)

Here you can find the source of appendHexString(StringBuffer buffer, byte data)

Description

Append hex string from byte to StringBuffer

License

Open Source License

Declaration

public static void appendHexString(StringBuffer buffer, byte data) 

Method Source Code

//package com.java2s;
/***************************************************************************
 * Copyright (c) 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from  w  ww .  j av a 2 s.  c  o m*/
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/

public class Main {
    public static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f', };

    /**
     * Append hex string from byte to StringBuffer
     */
    public static void appendHexString(StringBuffer buffer, byte data) {
        int positive = data < 0 ? ~data : data;
        buffer.append(HEX_DIGITS[positive >> 4]);
        buffer.append(HEX_DIGITS[positive & 0xf]);
    }
}

Related

  1. appendHexEscape(StringBuilder out, int codePoint)
  2. appendHexJavaScriptRepresentation(StringBuilder sb, char c)
  3. appendHexNumber(StringBuffer target, byte b)
  4. appendHexPair(byte b, StringBuffer sb)
  5. appendHexStream(StringBuilder sb, byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase)
  6. appendHexString(StringBuilder buffer, byte[] bytes)
  7. appendHexString(StringBuilder builder, int value)
  8. appendHexValue(final StringBuffer sb, final byte data)
  9. appendHexValue(StringBuffer buffer, byte b)