Skip to content

Commit c4cc20c

Browse files
Merge pull request #11 from ms10398/master
Added Implementation of Decimal to Octal
2 parents 24cbe03 + b9b5891 commit c4cc20c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Conversions/DecimalToOctal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function decimalToOctal(num) {
2+
var oct = 0,c=0;
3+
while (num > 0) {
4+
var r=num%8;
5+
oct=oct+(r*Math.pow(10,c++));
6+
num =Math.floor(num/ 8); // basically /= 8 without remainder if any
7+
}
8+
console.log("The decimal in octal is " + oct);
9+
}
10+
11+
decimalToOctal(2);
12+
decimalToOctal(8);
13+
decimalToOctal(65);
14+
decimalToOctal(216);
15+
decimalToOctal(512);

0 commit comments

Comments
 (0)