Java Hex Calculate toHexString(int b)

Here you can find the source of toHexString(int b)

Description

Returns a hex string representation of a 8 bit integer.

License

Apache License

Parameter

Parameter Description
b byte to convert to hex string

Return

hex value

Declaration

public static String toHexString(int b) 

Method Source Code

//package com.java2s;
/*//from ww  w  .j a v  a  2 s  .  c  om
 * BJAF - Beetle J2EE Application Framework
 * ???J2EE???????????
 * ??????2003-2015 ??? (www.beetlesoft.net)
 * 
 * ??????????????????
 *<http://www.apache.org/licenses/LICENSE-2.0>
 *????????????????????????
 *
 * ???????????????????????????????
 * ??? <yuhaodong@gmail.com/>.
 */

public class Main {
    private static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
            'F' };

    /**
     * Returns a hex string representation of a 8 bit integer. Very fast.
     * Returned hex values are in uppercase.
     * 
     * @param b
     *            byte to convert to hex string
     * 
     * @return hex value
     */
    public static String toHexString(int b) {
        char[] digits = new char[2];
        b = b & 255;

        digits[0] = hexDigits[b / 0x10];
        digits[1] = hexDigits[b % 0x10];

        return new String(digits);
    }
}

Related

  1. toHexString(final byte[] raw)
  2. toHexString(final int i)
  3. toHexString(final int value)
  4. toHexString(final long num, final char paddingChar, int min, int max)
  5. toHexString(int b)
  6. toHexString(int bits, int value)
  7. toHexString(int decimal, int stringLength)
  8. toHexString(int decimal, int stringLength)
  9. toHexString(int i)