Java Integer to Hex intToHex(int i)

Here you can find the source of intToHex(int i)

Description

Utility method to convert an int into hex, padded to two characters.

License

Open Source License

Parameter

Parameter Description
i Int to convert

Return

String a two character hex representation of i NOTE: this is a utility method and should be put somewhere more useful.

Declaration

public static String intToHex(int i) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.//from  w w w  .j a  v  a  2 s  .co m
 */

public class Main {
    /**
     * Utility method to convert an int into hex, padded to two characters.
     * handy for generating colour strings.
     *
     * @param i Int to convert
     * @return String a two character hex representation of i
     * NOTE: this is a utility method and should be put somewhere more useful.
     */
    public static String intToHex(int i) {
        String prelim = Integer.toHexString(i);

        if (prelim.length() < 2) {
            prelim = "0" + prelim;
        }

        return prelim;
    }
}

Related

  1. integerToHexString(final int aValue, final int aFieldWidth)
  2. integerToHexString(int value, int minBytes)
  3. intToFixedLengthHex(int value, int length)
  4. intToFixedLengthHexString(int i, int length)
  5. intToHex(int a)
  6. intToHex(int i)
  7. intToHex(int i)
  8. IntToHex(int i, int length)
  9. intToHex(int id)