Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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 {
            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;
    }
}