mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-05 08:17:33 +08:00
Merge pull request #51 from erugged93/patch-1
Update BinaryToOctal.java
This commit is contained in:
@ -29,7 +29,15 @@ public class BinaryToOctal {
|
||||
* @return The octal number
|
||||
*/
|
||||
public static int convertBinaryToOctal(int b) {
|
||||
|
||||
int o = 0, r=0, j =1 ;
|
||||
while(b!=0)
|
||||
{
|
||||
r = b % 10;
|
||||
o = o + r * j;
|
||||
j = j * 2;
|
||||
b = b / 10;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user