convert binary to octal java beginnerbook code example
Example 1: binary to octal in java
public class UsingtoOctalStringMethod
{
public static void main(String[] args)
{
String strNumber = "100101";
int binary = Integer.parseInt(strNumber, 2);
String strOctal = Integer.toOctalString(binary);
System.out.println("Octal value is: " + strOctal);
}
}
Example 2: binary to octal conversion java program
public class Main{
public static void main(String args[]) throws Exception{
String binary = "1100100";
int decimal = Integer.parseInt(binary,2);
System.out.println(Integer.toOctalString(decimal));
}
}