Computer Science, asked by Anonymous, 1 year ago

write a java program to convert octal to binary????

Answers

Answered by Anonymous
1
Hey user.☺,HeRe is yOur answer......!!☺⤵⤵
⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵⤵

❗❗_______________________________________❗❗☺⤵

;-) Java cord .....!⤵⤵☺


,import java.util.Scanner;

public class Exercise26 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int[] octal_numvalues = {0, 1, 10, 11, 100, 101, 110, 111};
long octal_num, tempoctal_num, binary_num, place;
int rem;
System.out.print("Input any octal number: ");
octal_num = in.nextLong();
tempoctal_num = octal_num;
binary_num = 0;
place = 1;
while (tempoctal_num != 0)
{
rem = (int)(tempoctal_num % 10);
binary_num = octal_numvalues[rem] * place + binary_num;
tempoctal_num /= 10;
place *= 1000;
}
System.out.print("Equivalent binary number: " + binary_num+"\n");
}
}


❗❗__________,_________________❗❗☺
Answered by ryan567
1
hey mate
In this program, the octal number to decimal to decimal at first. Then, the decimal number is converted to binary number.

public class OctalBinary { public static void main(String[] args) { int octal = 67; long binary = convertOctalToBinary(octal); System.out.printf("%d in octal = %d in binary", octal, 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; } }

When you run the program, the output will be:

67 in octal = 110111 in binary
hope it helps Mark as brainliest and follow me
Similar questions