27+ Java Decimal to Hexadecimal Converters

This post contains a total of 27+ Hand-Picked Java Decimal to Hexadecimal Converter examples. All the decimal and hexadecimal converters are made using Java programming language.

You can use the source codes of these programs for your own personal or educational use with credit’s to the original owner.

Related Posts

Click a Code to Copy it.

1. By Kalpit Patil

Made by Kalpit Patil. Java Program to convert Decimal Number to its Equivalent Hexadecimal Form. ( Source )

/** 
 * Eg 0: 69 --> 45
 * Eg 1: 11 --> B
 * Eg 2: 99 --> 63
*/
import java.util.*;
class DtoH
{
    static Scanner pk=new Scanner(System.in);
    int n;
    int t;
    String s;
    String T;
    DtoH()
    {
        n=0;
        s="";
        t=0;
        T="";
    }
    void input()
    {
        System.out.println("Enter a Decimal Number.");
        n=pk.nextInt();
        t=n;
    }
    void compute()
    {
        while(t>0)
        {
            int r=t%16;
            if(r>9&&r<16)
            {
                switch(r)
                {
                    case 10:
                    {
                        s+="A";
                        break;
                    }
                    case 11:
                    {
                        s+="B";
                        break;
                    }
                    case 12:
                    {
                        s+="C";
                        break;
                    }
                    case 13:
                    {
                        s+="D";
                        break;
                    }
                    case 14:
                    {
                        s+="E";
                        break;
                    }
                    case 15:
                    {
                        s+="F";
                        break;
                    }
                }
                t=t/16;
            }
            else
            {
                s+=r;
                t=t/16;
            }
        }
    }
    void reverse()
    {
        int l=s.length();
        for(int i=l-1;i>=0;i--)
        {
            char a=s.charAt(i);
            T+=a;
        }
    }
    void print()
    {
        System.out.println("Decimal Number : "+n);
        System.out.println("HexaDecimal Form : "+T);
    }
    public static void main(String args[])
    {
        DtoH kp=new DtoH();
        kp.input();
        kp.compute();
        kp.reverse();
        kp.print();
    }
}

2. By N.Venkatesh

Made by N.Venkatesh. ( Source )

import java.util.Scanner;
public class Program
{
	public static void main(String[] args) {
	String HD="0123456789ABCDEF";
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int i=0;
	String h="";
	while(n!=0){
	    h+=HD.charAt(n%16);
	    n/=16;
	}
	StringBuffer b=new StringBuffer(h);
	System.out.println(b.reverse());
	}
}

3. By alian pradeep

Made by alian pradeep. ( Source )

public class Program
{
    public static void main(String[] args) {
    String s="1101";
    int pow=0;
    int ans=0;
    for(int i=s.length()-1;i>=0;i--){
        int val=Character.getNumericValue(s.charAt(i));
        ans=ans+val*(int)Math.pow(2,pow++);
    }
    System.out.println(ans);
        
    }
}

4. By PARAMESHWARI V

Made by PARAMESHWARI V. ( Source )

import java.util.Scanner;
 public class JavaProgram { 
 public static void main(String args[]) { 
 int decnum, rem; String hexdecnum=""; /* digits in hexadecimal number system */ 
 char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  Scanner scan = new Scanner(System.in); 
           System.out.print("Enter Decimal Number : ");
   decnum = scan.nextInt();         
    while(decnum>0) { 
    rem = decnum%16;
     hexdecnum = hex[rem] + hexdecnum; decnum = decnum/16;
      }     
           System.out.print("Equivalent Hexadecimal Value of " + decnum + " is :\n");
       System.out.print(hexdecnum);
    } 
  }

5. By John Estel Peralta

Made by John Estel Peralta. ( Source )

import java.util.*;
public class Program
{
	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);
		int iDec = 0,iRem = 0,iCount = 0,iCounting = 0,iStop = 0,iRep = 0,iQuot = 0,iReminder = 0,iDecimal = 0;
		System.out.print("\n\tEnter Number: ");
		iDec = input.nextInt();
		iDecimal = iDec;
		System.out.println("\n\tDecimal to Hexadecimal\tResult\n");
		while(iDecimal != 0){
			
			iReminder = iDecimal % 16;
			iQuot = iDecimal / 16;
			System.out.println("\t"+iDecimal+"\t/ 16 = "+iQuot+" r\t"+iReminder);
			iDecimal /= 16;
		}
		iCounting = iDec;
		iRep = iDec;
		while(iCounting != 0){
			
			iCounting /= 16;
			iCount++;
		}
        System.out.print("\n\t"+iDec+" in Hexadecimal is: ");
		while(iCount != 0){
			
		    while(iStop != iCount){
				
				iRem = iDec % 16;
			    iDec /= 16;
				iStop++;
				if(iStop == iCount){
					
					iStop = 0;
					break;
				}
		}
		switch(iRem){
			
			case 10:
			System.out.print("a");
			break;
			case 11:
			System.out.print("b");
			break;
			case 12:
            System.out.print("c");
			break;
			case 13:
			System.out.print("d");
			break;
			case 14:
			System.out.print("e");
			break;
			case 15:
			System.out.print("f");
			break;
			default:
			System.out.print(""+iRem);
		}
		iCount--;
		iDec = iRep;
		}
		System.out.println("\n\n**********************************************************");
	}
}

6. By Java Joshua

Made by Java Joshua. A simple java program to get the hexadecimal value of a decimal number. The program also displays the octal and binary value. ( Source )

import java.util.Scanner;
class Convert
{
    Scanner scan;
    int num;
    void getVal()           //Enter a number in the Scanner
                            //it will print it out as binary
                            //octal and HexaDecimal
     {
          System.out.println("Decimal to HexaDecimal,Octal and Binary");
          scan = new Scanner(System.in);
          num = Integer.parseInt(scan.nextLine());
     }
    void convert()
      {
           String hexa = Integer.toHexString(num);
           System.out.println("HexaDecimal Value is : " + hexa);
           String octal = Integer.toOctalString(num);
           System.out.println("Octal Value is : " + octal);
           String binary = Integer.toBinaryString(num);
           System.out.println("Binary Value is : " + binary);
       }
}
class Decimal_Conversion
{
   public static void main(String args[])
    {
        Convert obj = new Convert();
         obj.getVal();
         obj.convert();
    }
}

7. By Vas

Made by Vas. The program converts decimals to integers and to hexadecimal (8 Bits). Change the “for (int counter = 1; counter < 128; counter++) {” value to the decimal number you want to use. ( Source )

/**
 * @author Vas
 * thanks to @John Wells for the support
 * 
 * */

public class Conversion {
    public static void main(String[] args) {

        System.out.println("Dezimal\tBinaer\tHexadezimal");
        System.out.println("___________________________");

        for (int counter = 1; counter < 128; counter++) {
            
String eightBits = "0000000"+Integer.toBinaryString(counter);
eightBits = eightBits .substring(eightBits.length()-8);          
String hex = Integer.toHexString(counter);   
            System.out.println(counter + "\t" + eightBits + "\t" + hex);
          
        }
    }
}

8. By Prantik Sarkar

Made by Prantik Sarkar. ( Source )

import java.util.Scanner;
/*
 * convert decimal to hexadecimal
 Example: 
 Input: Number in Decimal: 10
 Output: Hexadecimal value is: A
 */
public class DecToHex {
	public static void main(String[] args) {
//System.out.println("Enter a Decimal number");
Scanner sc= new Scanner(System.in);
		int num = sc.nextInt();
System.out.println("Number in Decimal: "+num);
		String hex = "";
		while (num > 0) {
			int rem = num % 16;
			hex = (convert(rem)) + hex;
			num = num / 16;
		}
System.out.println("Hexadecimal value is: " + hex);
	}//end of main
	private static String convert(int num) {
		String temp = "";
		if (num >= 0 && num <= 9)
			temp = temp + num;
		else
			temp = temp + (char) (num + 55);
		return temp;
	}
}//end of class

9. By Haris

Made by Haris. To operate this program choose 1 to convert decimals to hexadecimals or 2 to convert hexadecimals to decimals. Example 1: I want to convert 16777215 to hexadecimal so I press 1 and at the next line I enter 16777215.(outputs: ffffff) Example 2:I want to convert ffffff to decimal so I press 2 and at the next line I enter ffffff. (outputs: 16777215). ( Source )

/***************************
* Created : 12.4.2017      *
* Updated : 29.8.2017      *
***************************/

// #FFFFFF = white in hex colors

import java.util.Scanner;
public class decimal_to_hexadecimal_converter_and_vice_versa
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        try
        {
            int choice = Integer.parseInt(sc.nextLine());
        
            switch(choice)
            {
               case 1:
                    int decnum = Integer.parseInt(sc.nextLine());
                    System.out.println("Decimal number is: "+decnum);
        
                    Converter dth = new Converter();
                    dth.convertDtH(decnum);
               break;
               case 2:
                   String hexnum = sc.nextLine();
        
                   System.out.println("Hexadecimal number is: "+hexnum);
        
                   Converter htd = new Converter();
                   htd.convertHtD(hexnum);
               break;
               default:
               System.out.println("Error!\nInvalid input.");
            }
        }
        catch(Exception e)
        {
            System.out.println("Error!\nInvalid input.");
        }
    }
}

public class Converter
{
   public void convertDtH(int decnum)
   {
       String hexnum = Integer.toHexString(decnum);
       System.out.println("Hexadecimal number is: "+hexnum);
   }
    
   public void convertHtD(String hexnum)
   {
      int decnum = Integer.parseInt(hexnum,16);
      System.out.println("Decimal number is: "+decnum);
   }
}

10. By EoflaOE

Made by EoflaOE. This converts the number to hexadecimal letters starting from 0 to F. They consist of 16 characters. ( Source )

import java.util.Scanner;

public class Program
{
    public static String toHex(int number){
        int mod;
        char[] chars = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
        String result = "";
        while(number>0){
            mod=number%16;
            result=chars[mod]+result;
            number=number/16;
        }
        return result;
    }
    public static void main(String[] args) {
        System.out.println(toHex(new Scanner(System.in).nextInt()));
    }
}

11. By GAURAV JAISWAL

Made by GAURAV JAISWAL. ( Source )

import java.util.Scanner;
public class Dec_To_Hex
{
    public static void main(String args[])
    {
        int i,n,d,l,c,j;
        double p;
        String r="",rev="";
        char ch,chr;
        boolean check=true;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a decimal number to convert it to hexadecimal:");
        p = sc.nextDouble();
        n = (int)p;
        if(n==0)
        check = false;
        p = p - n;
        while(n>0)
        {
            d = n % 16;
            n = n / 16;
            if((d>=10)&&(d<=15))
            {
                for(j=10,chr='A';j<=15;j++,chr++)
                {
                    if(d==j)
                    {
                        r = r + chr;
                        break;
                    }
                }
            }
            else
            {
                r = r + d;
            }
        }
        l = r.length()-1;
        for(i=l;i>=0;i--)
        {
            ch = r.charAt(i);
            rev = rev + ch;
        }
        if(p==0.0d)
        {
            System.out.println(rev);
            System.exit(0);
        }
        if(check==false)
        rev = rev + "0";
        rev = rev + ".";
        for(i=1;i<=6;i++)
        {
            p = p * 16;
            c = (int)p;
            p = p - c;
            if((c>=10)&&(c<=15))
            {
                for(j=10,chr='A';j<=15;j++,chr++)
                {
                    if(c==j)
                    {
                        rev = rev + chr;
                        break;
                    }
                }
            }
            else
            {
                rev = rev + c;
            }
            if(p==0.0d)
            break;
        }
        System.out.println(rev);
    }
}

12. By Akash Middinti

Made by Akash Middinti. ( Source )

import java.util.Scanner;

public class Program
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int decimal = sc.nextInt();
	    sc.close();
	    System.out.println("Binary - "+Integer.toString(decimal,2));
	    System.out.println("Octal - "+Integer.toString(decimal,8));
	    System.out.println("Hexa-decimal - "+Integer.toString(decimal,16));
		
	}
}

13. By Emmanuel HΓΆfer

Made by Emmanuel HΓΆfer. ( Source )

import java.util.*;

final class MyClass {
    public static void main(String[ ] args) 
    {
        Scanner sc = new Scanner (System.in);
        
        ArrayList <String> hexa = new ArrayList ();
        
        int number = sc.nextInt();
        int x = number;
        
        String h="";
        while (x>0)
        {
        x=x%16;
        number = number/16;
        
        switch (x){
        case 0: h="0";break;
        case 1: h="1";break;
        case 2: h="2";break;
        case 3: h="3";break;
        case 4: h="4";break;
        case 5: h="5";break;
        case 6: h="6";break;
        case 7: h="7";break;
        case 8: h="8";break;
        case 9: h="9";break;
        case 10: h="A";break;
        case 11: h="B";break;
        case 12: h="C";break;
        case 13: h="D";break;
        case 14: h="E";break;
        case 15: h="F";break;
        
        }
        hexa.add(h);
        if (number!=0)
        {
        x=number;
        }
        else {break;}
        }
        String result = "The hexadecimal number is: ";
           for(int i=hexa.size()-1;i>-1;i--)
           {
           
            String n=hexa.get(i);
            result +=n;
           
           }  
           System.out.println(result);
    }
}

14. By John Calvin Santos

Made by John Calvin Santos. ( Source )

import java.util.Scanner;

public class Methodss {

 static Scanner user = new Scanner(System.in);
 
  public static void main(String[] args) {

      System.out.print("Enter decimal to cconvert into binary: ");
      int binary = user.nextInt();
      
      System.out.println(Integer.toHexString(binary));
    
 }
    }

15. By Dev

Made by Dev. An easy way to convert any decimal to Hexadecimal. ( Source )

import java.util.Scanner;

public class DecimalConversion
{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        if(scanner.hasNextLong()) {
            long decimalNum = scanner.nextLong();
            System.out.println(decimalNum + " in Hex: " + Long.toHexString(decimalNum));
        }
        else {
           System.out.println("I want only a number!");
        }
    }
}

16. By Debtanu Mukherjee

Made by Debtanu Mukherjee. ( Source )

import java.util.*;
public class Converter
{
    public static void main(String[] args) {
     Scanner sc= new Scanner(System.in);
     System.out.println("Enter a number");
     int a = sc.nextInt();
     String s="";
     while(a>0)
     {
         int rem= a%16;
         if(rem<10)
         s=s+(rem);
         else
         switch(rem)
         {
             case 10:
             s+='A';
             break;
             
             case 11:
             s+='B';
             break;
             
             case 12:
             s+='C';
             break;
             
             case 13:
             s+='D';
             break;
             
             case 14:
             s+='E';
             break;
             
             case 15:
             s+='F';
             break;
         }
         a/=16;
     }
     for(int i=s.length()-1;i>=0;i--)
     {
         System.out.print(s.charAt(i));
     }
    }
}

17. By ÁÑÀÑYÁÀBHÎK

Made by ÁÑÀÑYÁÀBHÎK. ( Source )

import java.util.Scanner;
public class HexadecimalToDecimal
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter an integer of the decimal number system");
        int d=sc.nextInt();
        String hex="";
        while(d!=0)
        {
            int w=d%16;
            if(w==10)
            hex='A'+hex;
            else if(w==11)
            hex='B'+hex;
            else if(w==12)
            hex='C'+hex;
            else if(w==13)
            hex='D'+hex;
            else if(w==14)
            hex='E'+hex;
            else if(w==15)
            hex='F'+hex;
            else
            hex=w+hex;
            d=d/16;
        }
        System.out.println("Hexadecimal number="+hex);
    }
}

18. By Mikhail Pashkov

Made by Mikhail Pashkov. ( Source )

import java.util.Scanner;

/*  -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 * β€’Decimal to Hexadecimal converterβ€’
 *  =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 * input examples: 
 *         1345
 *         1118481
 *         16581375
 *           ...
 */

public class DecToHex
{
    public static void main(String[] args) {
    
        final char[] ch = {'0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        
        System.out.println("Type dec number");
        long decInput = 
            new Scanner(System.in).nextLong();
            
        System.out.println(
             "(10) " + decInput);
        
        String hexOutput = "";
        int rem;
        do {
           rem = (int)(decInput % 16);
           hexOutput = ch[rem] + hexOutput;
           decInput /= 16;
        } while (decInput != 0);
        
        System.out.println(
             "(16) " + hexOutput);
    }
}

19. By Malek Alsset

Made by Malek Alsset. Change the decimal number at line ‘ int n = 282;’. ( Source )

import java.io.*; 

class MA  
{ 

    // function to convert decimal to hexadecimal 

    static void decToHexa(int n) 

    {    

        // char array to store hexadecimal number 

        char[] hexaDeciNum = new char[100]; 

       

        // counter for hexadecimal number array 

        int i = 0; 

        while(n!=0) 

        {    

            // temporary variable to store remainder 

            int temp  = 0; 

           

            // storing remainder in temp variable. 

            temp = n % 16; 

           

            // check if temp < 10 

            if(temp < 10) 

            { 

                hexaDeciNum[i] = (char)(temp + 48); 

                i++; 

            } 

            else

            { 

                hexaDeciNum[i] = (char)(temp + 55); 

                i++; 

            } 

           

            n = n/16; 

        } 

       

        // printing hexadecimal number array in reverse order 

        for(int j=i-1; j>=0; j--) 

            System.out.print(hexaDeciNum[j]); 

    } 

      

    public static void main (String[] args)  

    { 

        int n = 2545; 

        decToHexa(n); 

    } 
} 

20. By Ritik Sachan

Made by Ritik Sachan. ( Source )

import java.util.*;
class happy
{
    public static void main(String args[])
    {
        Scanner sc =new Scanner(System.in);
        System.out.println("enter the no.");
        
        String s1="";
        int n=sc.nextInt();
        int d;
        if(n<1)
        {
            System.out.println("Invalid input");
            }
            else
            {
                while(n>15)
                {
                    d=n%16;
                    if(d>9)
                    {
                        s1=s1+(char)(d+55);
                    }
                    else
                    {
                     s1=s1+d;
                     }
                    
                        n=n/16;
                }
                   if(n>9)
                    {
                        s1=s1+(char)(n+55);
                    }
                else
                {
                s1=s1+n;
                }
}

StringBuffer s=new StringBuffer(s1);
s=s.reverse();
System.out.println(s);
}
}

21. By matheus

Made by matheus. ( Source )

import java.util.Scanner;
public class Decimal_Hexadecimal {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        long number = in.nextLong();

        if (number > 0) {
            Convert con = new Convert(number);
            System.out.println(con.getHexaDecimal());
            
        } else {
        
            System.out.println("Sorry, I am working in a conversion with\nnegative numbers!");
            
        }
        System.out.println("\n\n    Thanks\n        Matheus Rambo!");
    }

}

class Convert {

    private String hexaDecimal = null;
    private int times = 0; // its use to create
    // the length of the array on the method
    // mod

    public Convert(long valueDecimal) {

        byte value = divideValue(valueDecimal);
        hexaDecimal = switchElements(value);
        
        
        int value1[] = mod(valueDecimal);

        for(int x = value1.length -1 ; x >= 0; x--){
            hexaDecimal += switchElements(value1[x]);
        }
        

    }

    /**
     * Checks if the String inserted is a number!
     *
     * @param number
     * @return
     */
     /*
    public boolean isNumber(String number) {

        int count = 0;

        char numbers[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        char actual;

        for (int i = 0; i < number.length(); i++) {

            actual = number.charAt(i);

            for (int z = 0; z < numbers.length; z++) {

                if (actual == numbers[z]) {
                    ++count;
                }
            }
        }
        // if the count has the same value that the length of the number
        // will return true!
        return count == number.length();
    }*/

    /**
     * It's long because can be a numeral with 19 numbers!
     *
     * @param value
     * @return
     */
    /**
     * Divide the value in 16
     *
     * @param value
     * @return
     */
    private byte divideValue(long value) {
        
        for(int i = 16; i < value;){
            value = value / 16;
            ++times;
            
        }
        return (byte)value;
    }

    private int[] mod(long value) {
        int mod = 0;
        int values [] = new int[times];
        byte count = 0;
        
        for(int i = 16; i < value; value = value / 16){
            mod = (int)value % 16;
            values[count] = mod;
            ++count;
        }
        return values;
    }

    /**
     * table of the values in HexaDecimal
     *
     * @param value
     * @return the hexaDecimal number!
     */
    private String tableHexaDecimal(int value) {

        switch (value) {

            case 10:
                return "A";
            case 11:
                return "B";
            case 12:
                return "C";
            case 13:
                return "D";
            case 14:
                return "E";
            case 15:
                return "F";
            default:
                return " ";

        }
    }

    /**
     * Switch the elements and return them in hexaDecimal
     *
     * @param numberDivided
     * @return
     */
    public String switchElements(byte numberDivided) {

        String hexa = "";
        // if the number is less than 10 return itself
              hexa += numberDivided < 10 ? numberDivided : tableHexaDecimal(numberDivided);


        return hexa;
    }
 
    /**
     * Overload of the method! 
     * @param numberMod
     * @return 
     */
    
    public String switchElements(int numberMod){
        String hexa = "";
        
        hexa += numberMod < 10 ? numberMod : tableHexaDecimal(numberMod);
        
        return hexa;
    }
    public String getHexaDecimal() {
        return hexaDecimal;
    }
}

22. By Amit Gahatraj

Made by Amit Gahatraj. ( Source )

// Decimal to Hexadecimal

import java.util.Scanner;
public class Converter{
	public static void main(String[] args) {
	   
	    Scanner input = new Scanner(System.in);
	    System.out.println("Enter any number: ");
	    int D=input.nextInt();
	    
	    String H="";
	    String Hexa ="";
	    
	    
	    for(D=D;D>0;){
	       int R= D %16;
	       int Q= D/16;
	       
	            if (R<10){
	              H= Integer.toString(R);
	            }
	            else {
	             switch (R){
	           case 10: 
	               H="A";break;
	           case 11: 
	               H="B";break;
	           case 12: 
	               H="C";break;
	           case 13: 
	               H="D";break;
	           case 14: 
	               H="E";break;
	           case 15: 
	               H="F";break;
	       }
	      
	            }
	            Hexa=H+Hexa; 
	             D=Q;
	    }
	                          
	    
	System.out.println(Hexa);	
	}
}


23. By Muhammad Mazhar

Made by Muhammad Mazhar. ( Source )


import java.util.Scanner;
import java.util.Stack;

public class DecimalToHexadecimal
{
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n ;
    System.out.println("Input Decimal Number: ") ;
    n = s.nextInt();
    Stack<Integer> hexadecimal = new Stack<>();
    int digit;
    while(n>0){
        digit = n % 16;
        hexadecimal.push(digit);
        n = n / 16;
    }
    int top = hexadecimal.size();
    System.out.print("Hexadecimal number is: ");
    while(top !=0){
        digit = hexadecimal.pop();
        System.out.print(digit);
        top--;
    }
        
    }
}

24. By Arnab Ghosh

Made by Arnab Ghosh. Enter your decimal number in the line “printint (32);”. ( Source )

public class Program
{    
    public static void printint(int number){
        String conversion ="0123456789ABCDEF";
        int base =16;
        int digit =(number%base);
        //System.out.println(digit);
        number =number / base;
        if(number != 0){
            printint (number );
        }
       System.out.print(conversion.charAt(digit));
    }
    public static void main(String[] args) {
        printint (32);
    }
}

25. By Reneviel Arias

Made by Reneviel Arias. ( Source )

import java.util.Scanner;
public class go_act_14 {
    public static void main(String[] args) {
    
    int dec, rem;
    String hexd ="";
   char hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    
    Scanner myObj= new Scanner(System.in);
    dec = myObj.nextInt();
    System.out.println("Enter Decimal Number: " + dec);
    
    
    while(dec>0)
{
     rem = dec%16;
     hexd = hex[rem] + hexd;
     dec = dec/16;
}
    System.out.println("Equivalent of hexadecimal value is "+ hexd);
}
}

26. By Ayush kumar

Made by Ayush kumar. ( Source )

import java.util.Scanner;
class Conversion
{
    public static void main(String args[])
    {
        Scanner ins=new Scanner(System.in);
        System.out.println("Enter a decimal number");
        int n=ins.nextInt();
        String h="";
        while(n>0)
        {
            int d=n%16;
            if(d<=9)
            h=d+h;
            else
            h=(char)(55+d)+h;
            n=n/16;
        }
        System.out.println("Hexadecimal equivalent="+h);
    }
}

27. By Lord Teacrumble

Made by Lord Teacrumble. ( Source )

import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.lang.Math;
import java.util.Collections;
import java.util.HashMap;
public class Program
{
    public static void main(String[] args){
    /*
    ////////////////////////////////////////
    ENTER hex, bin OR dec AS STARTVALUE
    ENTER ACTUAL VALUE
    GET RESULTS
    ////////////////////////////////////////
    */
    try{
        Scanner read = new Scanner(System.in);
        System.out.println("Enter the type of number you want to convert (hex/bin/dec)");
        String choice = read.next();
        switch(choice){
            case "hex":
            System.out.println("Enter a hexadecimal number");
            String hexa = read.next();
            checkHexa(hexa);
            System.out.println("Hexadecimal notation : " + hexa);
            System.out.println("Decimal notation : " + hexDec(hexa));
            System.out.println("Binary notation : " + hexBin(hexa));
            break;
            case "dec":
            System.out.println("Enter a decimal number");
            int decimal = Integer.parseInt(read.next());
            System.out.println("Decimal notation : " + decimal);
            System.out.println("Binary notation : " + decBin(decimal));
            System.out.println("Hexadecimal notation : " + decHex(decimal));
            break;
            case "bin":
            System.out.println("Enter a binary");
            int binary = Integer.parseInt(read.next());
            System.out.println("Binary notation : " + binary);
            System.out.println("Decimal notation : " + binDec(binary));
            System.out.println("Hexadecimal notation : " + binHex(binary));
            break;
            default:
            System.out.println("choose one of the 3 choices \n(hex/bin/dec) " + choice);
        }
    }
    catch(Exception ex){
         System.out.println("woopsie " + ex.getMessage());
    }
    }



    /*
    Converts decimal to hexadecimal
    */
    public static String decHex(int number){
        if(number < 16){
            return hexNum(number);
        }
        else{
            return decHex(number/16) + hexNum(number%16);
        }
    }
    
    
    /*
    Converts decimal numbers to hexadecimal numbers
    */
    public static String hexNum(int num){
        String result;
        switch(num){
            case 10:
            result = "A";
            break;
            case 11:
            result = "B";
            break;
            case 12:
            result = "C";
            break;
            case 13:
            result = "D";
            break;
            case 14:
            result = "E";
            break;
            case 15:
            result = "F";
            break;
            default:
            result = "" + num;
            break;
        }
        return result;
    }
    
    
    /*
    Converts decimals to binary
    */
    private static String decBin(int number){
        if(number%2 == 1){
            if(number == 1){
                return "1";
            }
            else{
                return decBin(number/2) + "1";
            }
        }
        else{
            return decBin(number/2) + "0";
        }
    }
    
    /*
    check if input = binary
    */
    
    private static void checkBin(int[] bin) throws Exception {
    
        for(int t: bin){
            if(t>1){
            throw new Exception("enter a binary number");
            }
        }
    }
    
    
    /*
    Binary to decimal
    */
    
    private static String binDec(int binary) throws Exception {
    try{
        String sBinar = Integer.toString(binary);
        int[] split = new int[sBinar.length()];
        for(int c= sBinar.length()-1; c>= 0; c--){
            split[c] = sBinar.charAt(c)-'0';
        }
        checkBin(split);
        int multi = 1;
        int result = 0;
        for(int i = sBinar.length()-1; i>=0; i--){
        result += split[i]*multi;
        multi*= 2;
        }
        
        return Integer.toString(result);
        }
        catch (Exception ex){
            throw new Exception(ex.getMessage());
        }
    }
    
    
    /*
    binary to hexadecimal
    */
    
    private static String binHex(int binary) throws Exception {
        String sBinar = Integer.toString(binary);
        int[] split = new int[sBinar.length()];
        for(int c= sBinar.length()-1; c>= 0; c--){
            split[c] = sBinar.charAt(c)-'0';
        }
        int multi = 1;
        int counter = 0;
        int result = 0;
        List <String> results = new ArrayList <String>();
        for(int i = sBinar.length()-1; i>=0; i--){
            counter++;
            result += split[i]*multi;
            multi*=2;
            if(counter == 4|| i==0){
                results.add(hexNum(result));
                multi = 1;
                counter = 0;
                result = 0;
            }
        }
        Collections.reverse(results);
        String total = "";
        for(Iterator <String> i = results.iterator(); i.hasNext(); ){
        String s = i.next();
            total+= s;
        }
        return total;
    }
    
    
    
    /*
    
    Check if hexadecimal
    
    */
    
    private static void checkHexa(String hex) throws Exception{
        char[] arrHex;
        arrHex = hex.toCharArray();
        for(char c: arrHex){
            if(!((c>= 48 && c<=57)||(c>=65 && c<=90))){
                throw new Exception("this is not a valid hexadecimal number");
            }
        }
    }
    
    /*
    hexadecimal numbers to decimal numbers
    */
    
    
    private static int toDec(char hexn){
        String returnNumber;
        switch(hexn){
            case 'A':
            returnNumber = "10";
            break;
            case 'B':
            returnNumber = "11";
            break;
            case 'C':
            returnNumber = "12";
            break;
            case 'D':
            returnNumber = "13";
            break;
            case 'E':
            returnNumber = "14";
            break;
            case 'F':
            returnNumber = "15";
            break;
            default:
            returnNumber="" + hexn;
        }
        return Integer.parseInt(returnNumber);
    }
    
    /*
    hexadecimal to decimal
    */
    private static String hexDec(String hex){
        char[] arrHex;
        arrHex = hex.toCharArray();
        int result = 0;
        List<Integer> arrDec = new ArrayList <Integer>();
        for(int e = 0; e<arrHex.length; e++){
        arrDec.add(toDec(arrHex[e]));
        }
        Collections.reverse(arrDec);
        int counter = 0;
        for(Iterator <Integer> i = arrDec.iterator(); i.hasNext(); ){
            int num = i.next();
            result += num*(Math.pow(16, counter));
            counter++;
            }
        return Integer.toString(result);
    }
    
    /*
    hexadecimal to binary
    */
    
    private static String hexBin(String hexadec){
        char[] arrayH;
        arrayH = hexadec.toCharArray();
        HashMap<Character,String> dict = new HashMap<Character,String>();
        String result = "";
        dict.put('1',"0001");
        dict.put('2',"0010");
        dict.put('3',"0011");
        dict.put('4',"0100");
        dict.put('5',"0101");
        dict.put('6', "0110");
        dict.put('7', "0111");
        dict.put('8', "1000");
        dict.put('9', "1001");
        dict.put('A', "1010");
        dict.put('B', "1011");
        dict.put('C', "1100");
        dict.put('D', "1101");
        dict.put('E', "1110");
        dict.put('F', "1111");
        for(char c: arrayH){
            result += dict.get(c);
        }
        return result;
    }
    
}

28. By jasbir

Made by jasbir. ( Source )

import java.util.Scanner;

class convert
{
public String  conversion( int a,int b)
{
 char[] hex = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
 
 String  arr = "";
 
 while(a>0)
 {
    arr+=hex[a%b];
    a/=b;
 }
 return arr;
}
}



public class DecConversion
{
    public static void main(String[] args) {
    Scanner input=new Scanner(System.in);
    System.out.println("enter the decimal   number");
    int num=input.nextInt();
    System.out.println("enter the base");
    int base = input.nextInt() ;
    convert c =new convert();
    String str = c.conversion(num,base);


    for(int i=str.length()-1;i>=0;i--)
    System.out.print(str.charAt(i));
    }
}