-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethod 1
More file actions
40 lines (33 loc) · 947 Bytes
/
Method 1
File metadata and controls
40 lines (33 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Java program to convert octal number to binary number
class Main
{
public static void main(String args[])
{
int octal = 12;
//Declaring variable to store decimal number
int decimal = 0;
//Declaring variable to use in power
int n = 0;
//writing logic for the octal to decimal conversion
while(octal > 0)
{
int temp = octal % 10;
decimal += temp * Math.pow(8, n);
octal = octal/10;
n++;
}
int binary[] = new int[20];
int i = 0;
//writing logic for the decimal to binary conversion
while(decimal > 0)
{
int r = decimal % 2;
binary[i++] = r;
decimal = decimal/2;
}
//printing result
System.out.print("Binary number : ");
for(int j = i-1 ; j >= 0 ; j--)
System.out.print(binary[j]+"");
}
}