Java Integer to intToEightHexString(final int value)

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

Description

Convert an integer to a eight character Hex string, with leading zeroes.

License

Open Source License

Parameter

Parameter Description
value a parameter

Return

String

Declaration


public static String intToEightHexString(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 eight character Hex string, with leading zeroes.
     * Always return upper case./* w w w  . ja v  a  2s .  co  m*/
     *
     * @param value
     *
     * @return String
     */

    public static String intToEightHexString(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 & 0xFFFFFFFF);

        // There must be a better way?!
        if (strHex.length() == 0) {
            // Not needed?
            buffer.append("00000000");
        } else if (strHex.length() == 1) {
            buffer.append("0000000");
            buffer.append(strHex);
        } else if (strHex.length() == 2) {
            buffer.append("000000");
            buffer.append(strHex);
        } else if (strHex.length() == 3) {
            buffer.append("00000");
            buffer.append(strHex);
        } else if (strHex.length() == 4) {
            buffer.append("0000");
            buffer.append(strHex);
        } else if (strHex.length() == 5) {
            buffer.append("000");
            buffer.append(strHex);
        } else if (strHex.length() == 6) {
            buffer.append("00");
            buffer.append(strHex);
        } else if (strHex.length() == 7) {
            buffer.append("0");
            buffer.append(strHex);
        } else {
            // We must remove any leading 'FF's caused by sign extension...
            buffer.append(strHex.substring(0, 8));
        }

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

Related

  1. intToDouble(int coordinate)
  2. intToDouble(int[] input)
  3. intToDouble100000(int i)
  4. intToDoubleArray(int[] labels)
  5. intToEightByte(long value, byte[] dest, int off)
  6. intToEle(int integEle)
  7. intToEncodedID(int input)
  8. IntToEnode62(Integer int10)
  9. IntToEnode62(Integer int10)