octal to binary in java

Let’s learn octal to binary in java.

octal to binary in java

Task here is to convert octal number to binary number.

An octal number is base 8 number system which uses digits from 0 to 7.

Also read – octal to hexadecimal in java

Binary number is expressed in base 2 binary numercal system which uses two digits 0 and 1.

In the below java program we take input from user using Scanner class.

import java.util.Scanner;
public class OctalToBinaryJava
   public static void main(String[] args)
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter octal number: ");
      int octal = Integer.parseInt(sc.nextLine(), 8);
      String strBinary = Integer.toBinaryString(octal);
      System.out.println("Binary value is: " + strBinary);


Please enter octal number:
Binary value is: 1100

Also read – octal to decimal in java

Also read – decimal to binary java