Java Integer to Hex integerToHex(final Object value, final int desimals)

Here you can find the source of integerToHex(final Object value, final int desimals)

Description

integer To Hex

License

Open Source License

Declaration

public static String integerToHex(final Object value, final int desimals) 

Method Source Code

//package com.java2s;
// and/or modify it under the terms of the GNU General Public License 

public class Main {
    private static String zeroes = "00000000000000000000000000000000";

    public static String integerToHex(final Object value, final int desimals) {
        long tmp;
        if (value instanceof Byte) {
            tmp = ((Byte) value).byteValue() & 0xFF;
        } else if (value instanceof Short) {
            tmp = ((Short) value).shortValue() & 0xFFFF;
        } else if (value instanceof Long) {
            tmp = ((Long) value).longValue() & 0xFFFFFFFF;
        } else {//from   w ww  . j ava2s. c o m
            tmp = ((Number) value).longValue();
        }
        String str = Long.toString(tmp, 16).toUpperCase();
        if (desimals == 0 || str.length() == zeroes.length()) {
            return str;
        }
        return zeroes.substring(0, desimals - str.length()) + str;
    }
}

Related

  1. int2HexString(int n)
  2. int2hexString(int x)
  3. int2HexString(StringBuilder buf, int value)
  4. int2HexZeroPad(int i)
  5. integerToHex(final Object value, final int desimals)
  6. integerToHex(int val)
  7. integerToHexShort(int value)
  8. integerToHexString(final int aValue, final int aFieldWidth)
  9. integerToHexString(int value, int minBytes)