Skip to content

Commit 10889f4

Browse files
authored
Update BinaryToOctal.java
added logic to convert binary to octal
1 parent 4e14531 commit 10889f4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Conversions/BinaryToOctal.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ public static void main(String args[]) {
2929
* @return The octal number
3030
*/
3131
public static int convertBinaryToOctal(int b) {
32-
32+
int o = 0, r=0, j =1 ;
33+
while(b!=0)
34+
{
35+
r = b % 10;
36+
o = o + r * j;
37+
j = j * 2;
38+
b = b / 10;
39+
}
40+
return o;
3341
}
3442

3543
}

0 commit comments

Comments
 (0)