Java Hex Calculate toHexByte(int bite)

Here you can find the source of toHexByte(int bite)

Description

Converts a byte to a hex String.

License

Open Source License

Parameter

Parameter Description
bite the byte to convert

Declaration

public static String toHexByte(int bite) 

Method Source Code

//package com.java2s;
/*//  w w  w  .  j  a  v  a  2  s  . c  o m
* Copyright 2004 - 2008 Christian Sprajc. All rights reserved.
*
* This file is part of PowerFolder.
*
* PowerFolder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* PowerFolder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PowerFolder. If not, see <http://www.gnu.org/licenses/>.
*
* $Id: ColorUtil.java 6135 2008-12-24 08:04:17Z harry $
*/

public class Main {
    /** A table of hex digits */
    private static final char[] hexDigit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     * Converts a byte to a hex String.
     *
     * @param bite
     *           the byte to convert
     * @return
     */
    public static String toHexByte(int bite) {
        return String.valueOf(toHexNibble(bite >> 4)) + toHexNibble(bite);
    }

    /**
     * Convert a nibble to a hex character
     *
     * @param nibble
     *            the nibble to convert.
     * @return
     */
    public static char toHexNibble(int nibble) {
        return hexDigit[(nibble & 0xF)];
    }
}

Related

  1. toHexaString(byte[] data)
  2. toHexaString(int value)
  3. toHexByte(byte b)
  4. toHexByte(byte b, StringBuffer sb)
  5. toHexByte(final char ch1, final char ch2)
  6. toHexByte(int i)
  7. toHexByteArray(final byte[] buffer)
  8. toHexBytes(byte[] bytes)
  9. toHexBytes(byte[] data)