1public class ConvertHexToDecimal
2{
3 public static void main(String[] args)
4 {
5 String strHex = "b";
6 int decimal = Integer.parseInt(strHex, 16);
7 System.out.println("Decimal number : " + decimal);
8 }
9}
1import java.util.Scanner;
2public class BinaryToDecimalDemo
3{
4 public static void main(String[] args)
5 {
6 int number, decimal = 0, a = 0;
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Please enter binary number: ");
9 String strBinary = sc.nextLine();
10 number = Integer.parseInt(strBinary);
11 while(number != 0){
12 decimal += (number % 10) * Math.pow(2, a);
13 number = number / 10;
14 a++;
15 }
16 System.out.println("Decimal number: " + decimal);
17 sc.close();
18 }
19}