Java Hex String Create appendHex(final StringBuffer buf, final byte i)

Here you can find the source of appendHex(final StringBuffer buf, final byte i)

Description

append Hex

License

Apache License

Declaration

public static void appendHex(final StringBuffer buf, final byte i) 

Method Source Code

//package com.java2s;
/*/*from  w ww  .j a  va 2  s  .c  o m*/
 * Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

public class Main {
    public static void appendHex(final StringBuffer buf, final byte i) {
        buf.append(Character.forDigit((i & 0xf0) >> 4, 16));
        buf.append(Character.forDigit((i & 0x0f), 16));
    }

    public static void appendHex(final StringBuffer buf, final int i) {
        buf.append(Integer.toHexString((i >> 24) & 0xff));
        buf.append(Integer.toHexString((i >> 16) & 0xff));
        buf.append(Integer.toHexString((i >> 8) & 0xff));
        buf.append(Integer.toHexString(i & 0xff));
    }
}

Related

  1. appendHex(final StringBuffer buf, final int i)
  2. appendHex(int color, StringBuffer buffer)
  3. appendHex(StringBuffer buf, int x)
  4. appendHex(StringBuffer buffer, byte b)