Java Convert Octal to Binary

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

 
 

Share on Google+Share on Google+

Java Convert Octal to Binary

Ads

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

Advertisements

Posted on: December 4, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles