Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Convert Octal to Binary in java

class Main {
  public static void main(String[] args) {
    int octal = 67;
    long binary = convertOctalToBinary(octal);
    System.out.println(octal + " in octal = " + binary + " in binary");
  }

  public static long convertOctalToBinary(int octalNumber) {
    int decimalNumber = 0, i = 0;
    long binaryNumber = 0;

    while (octalNumber != 0) {
      decimalNumber += (octalNumber % 10) * Math.pow(8, i);
      ++i;
      octalNumber /= 10;
    }

    i = 1;

    while (decimalNumber != 0) {
      binaryNumber += (decimalNumber % 2) * i;
      decimalNumber /= 2;
      i *= 10;
    }

    return binaryNumber;
  }
}
Comment

binary to octal conversion java program

// conversion of binary to octal in java..
public class Main{
    public static void main(String args[]) throws Exception{
        String binary = "1100100";                // binary number.. 
        int decimal = Integer.parseInt(binary,2); // converting binary to decimal
        System.out.println(Integer.toOctalString(decimal)); // 144 <= octal output..  
    }
}
Comment

Convert Octal to Binary in java

class Main {
  public static void main(String[] args) {
    int octal = 67;
    long binary = convertOctalToBinary(octal);
    System.out.println(octal + " in octal = " + binary + " in binary");
  }

  public static long convertOctalToBinary(int octalNumber) {
    int decimalNumber = 0, i = 0;
    long binaryNumber = 0;

    while (octalNumber != 0) {
      decimalNumber += (octalNumber % 10) * Math.pow(8, i);
      ++i;
      octalNumber /= 10;
    }

    i = 1;

    while (decimalNumber != 0) {
      binaryNumber += (decimalNumber % 2) * i;
      decimalNumber /= 2;
      i *= 10;
    }

    return binaryNumber;
  }
}
Comment

binary to octal conversion java program

// conversion of binary to octal in java..
public class Main{
    public static void main(String args[]) throws Exception{
        String binary = "1100100";                // binary number.. 
        int decimal = Integer.parseInt(binary,2); // converting binary to decimal
        System.out.println(Integer.toOctalString(decimal)); // 144 <= octal output..  
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: infinity constatn in java 
Java :: How to efficiently generate all combinations of well-formed parentheses for n pairs of them, in Java? 
Java :: enter key java 
Java :: use view binding in fragment 
Java :: java get distinct values from list 
Java :: coding collections clear method java 
Java :: react native android gif 
Java :: short java 
Java :: input java 
Java :: how to add transition between activities android studio 
Java :: int to binary java 
Java :: paper api maven 
Java :: How to create a disjoint-set data structure, in Java? 
Java :: Java forName() method 
Java :: object to array java 
Java :: round off java 2 decimal places 
Java :: why to use serializable with java bean 
Java :: Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.spi.LoggerContextFactory.isClassLoaderDependent()Z 
Java :: create file from byte array java 
Java :: min of an array java 
Java :: murtaza jafari 
Java :: android hide system bar programmatically 
Java :: create a toast message in android 
Java :: add seconds to today date and time java 
Java :: how to wait in java 
Java :: how to open an activity from a fragment 
Java :: java logger error 
Java :: java how to print a string[] 
Java :: execute code after delay java 
Java :: android localdatetime 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =