Java Decimal to Hex dec2hex(int dec)

Here you can find the source of dec2hex(int dec)

Description

dechex

License

Apache License

Declaration

public static String dec2hex(int dec) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String dec2hex(int dec) {
        String s = "";
        s = Integer.toHexString(dec).toUpperCase();
        if (s.length() % 2 != 0) {
            s = padleft(s, s.length() + 1, '0');
        }//from www  . j av  a 2  s . c o m
        return s;

    }

    public static String padleft(String oristr, int len, char alexin) {
        int strlen = oristr.length();
        String str = "";
        if (strlen < len) {
            for (int i = 0; i < len - strlen; i++) {
                str = str + alexin;
            }
        }
        str = str + oristr;
        return str;
    }
}

Related

  1. decimal2hex(int d)
  2. decimalToHex(int n)
  3. decimalToHexa(final int d)