75) Write a program to input a number in Hexadecimal form and convert it decimal form? (64 in Hexadecimal then
100 in decimal, 160, 161, ….)
import java.util.*;
public class Hexadecimal_in_Decimal
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a HEXADECIMAL number");
String b = sc.nextLine();
int a = b.length();
int m = 0;
int r = a-1;
int c = 0;
while(m<a)
{
char d = b.charAt(r);
int x = (int)Math.pow(16,m);
m++;
if(d=='0')
{
c=c+0*x;
}
else if(d=='1')
{
c=c+1*x;
}
else if(d=='2')
{
c=c+2*x;
}
else if(d=='3')
{
c=c+3*x;
}
else if(d=='4')
{
c=c+4*x;
}
else if(d=='5')
{
c=c+5*x;
}
else if(d=='6')
{
c=c+6*x;
}
else if(d=='7')
{
c=c+7*x;
}
else if(d=='8')
{
c=c+8*x;
}
else if(d=='9')
{
c=c+9*x;
}
else if(d=='a'||d=='A')
{
c=c+10*x;
}
else if(d=='B'||d=='b')
{
c=c+11*x;
}
else if(d=='c'||d=='C')
{
c=c+12*x;
}
else if(d=='D'||d=='d')
{
c=c+13*x;
}
else if(d=='e'||d=='E')
{
c=c+14*x;
}
else if(d=='F'||d=='f')
{
c=c+15*x;
}
r--;
}
System.out.println(b+" in DECIMAL = "+c);
}
}