Java Convert Octal to Binary


 

Java Convert Octal to Binary

In this tutorial, you will learn how to convert octal to binary.

In this tutorial, you will learn how to convert octal to binary.

Java Convert Octal to Binary

In this tutorial, you will learn how to convert octal to binary.

Java has provide different ways to change the number system of different numbers. You can convert and decimal to octal, decimal to binary, decimal to hexadecimal or vice versa. Here is an example of converting octal number to binary.

Example:

import java.io.*;
class ConvertOctalToBinary{
    public static void main(String[] args)throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter octal number: ");
        String oct = br.readLine();
        int i= Integer.parseInt(oct,8);
        String binary=Integer.toBinaryString(i);
        System.out.println("Octal Number: "+binary);
    }
}

Output:

Enter octal number: 32
Octal Number: 11010

Ads