Hexadecimal to Decimal, Octal & Binary in JAVA programming


import java.util.Scanner;

public class HexadecimaltoAll {

    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
        System.out.print("Enter a Hexadecimal number : ");
        String str=myScanner.nextLine();
       
        int num=Integer.parseInt(str,16);
       
        String decimal=Integer.toString(num);
        String octal=Integer.toOctalString(num);
        String binary=Integer.toBinaryString(num);
       
        System.out.println("Decimal value is : "+decimal);
        System.out.println("Binary value is : "+binary);
        System.out.println("Octal value is : "+octal);
    }

}
//Enter a Hexadecimal number : ABCD12
//Decimal value is : 11259154
//Binary value is : 101010111100110100010010
//Octal value is : 52746422

No comments:

Post a Comment