Java Decimal to Hex decimal2hex(int d)

Here you can find the source of decimal2hex(int d)

Description

decimalhex

License

LGPL

Declaration

public static String decimal2hex(int d) 

Method Source Code

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

public class Main {
    private static final String digits = "0123456789ABCDEF";

    public static String decimal2hex(int d) {
        if (d == 0)
            return "0";
        StringBuilder hex = new StringBuilder();
        while (d > 0) {
            int digit = d % 16;
            hex.insert(0, digits.charAt(digit));
            d = d / 16;/*from   ww w  .  ja v a 2 s  . c  o m*/
        }
        return hex.toString();
    }
}

Related

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