Java Integer to intToTwoHexString(final int value)

Here you can find the source of intToTwoHexString(final int value)

Description

Convert an integer to a two character Hex string, with leading zero.

License

Open Source License

Parameter

Parameter Description
value a parameter

Return

String

Declaration


public static String intToTwoHexString(final int value) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    /***********************************************************************************************
     * Convert an integer to a two character Hex string, with leading zero.
     * Always return upper case.//from   w  w w.j a  v  a 2  s. co m
     *
     * @param value
     *
     * @return String
     */

    public static String intToTwoHexString(final int value) {
        final StringBuffer buffer;
        final String strHex;

        buffer = new StringBuffer();

        // Returns a string representation of the *integer* argument as an unsigned integer in base 16
        strHex = Integer.toHexString(value & 0xFF);

        if (strHex.length() == 0) {
            // Not needed?
            buffer.append("00");
        } else if (strHex.length() == 1) {
            buffer.append("0");
            buffer.append(strHex);
        } else {
            // We must remove any leading 'FF's caused by sign extension...
            buffer.append(strHex.substring(0, 2));
        }

        return (buffer.toString().toUpperCase());
    }
}

Related

  1. intToTime(int value)
  2. intToTriplePlace(int i)
  3. intToTwoByte(int value, byte[] destination, int offset)
  4. intToTwoBytes(int value)
  5. intToTwoDigitString(int integer)
  6. intToUByte(int i)
  7. intToULong(int signed)
  8. intToUnsigned(int signed)
  9. intToUnsignedByte(int i)