Hexadecimal to Decimal

import java.util.Scanner;
class HexaDecimalToDecimal
{
    public static void main(String args[])
    {
        String hexdec ;
        String hex= "0123456789ABCDEF";
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter Hexadecimal Number : ");
        hexdec = sc.nextLine();
        hexdec = hexdec.toUpperCase();
        int decimal = 0;
        for (int i = 0; i < hexdec.length(); i++)
        {
                 char ch = hexdec.charAt(i);
                 int  in= hex.indexOf(ch);
                 decimal = 16*decimal + in;
        }
        System.out.print("Decimal Number is " + decimal);
    }    
}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...