Java Hex Calculate toHexString(int i)

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

Description

Convert an integer to a 16-digit hex string.

License

LGPL

Declaration

private static String toHexString(int i) 

Method Source Code

//package com.java2s;
/*/* ww  w . j a v a2  s  . co m*/
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

public class Main {
    /**
     *  Convert an integer to a 16-digit hex string.
     */
    private static String toHexString(int i) {
        String s = Integer.toHexString(i).toUpperCase();

        if (s.length() < 8)
            return "00000000".substring(8 - s.length()) + s;
        else
            return s;
    }

    /**
     *  Convert a long to a 16-digit hex string.
     */
    private static String toHexString(long l) {
        String s = Long.toHexString(l).toUpperCase();

        if (s.length() < 16)
            return "0000000000000000".substring(16 - s.length()) + s;
        else
            return s;
    }
}

Related

  1. toHexString(int decimal, int stringLength)
  2. toHexString(int i)
  3. toHexString(int i)
  4. toHexString(int i)
  5. toHexString(int i)
  6. toHexString(int i)
  7. toHexString(int i, int digits)
  8. toHexString(int input)
  9. toHexString(int iValue)