Added Implementation of Decimal to Octal

This commit is contained in:
Mohit Sharma
2017-08-20 00:42:57 +05:30
committed by GitHub
parent b9fea2c907
commit 9e1d8cfd3c

View File

@ -0,0 +1,15 @@
function decimalToOctal(num) {
var oct = 0,c=0;
while (num > 0) {
var r=num%8;
oct=oct+(r*Math.pow(10,c++));
num =Math.floor(num/ 8); // basically /= 8 without remainder if any
}
console.log("The decimal in binary is " + oct);
}
decimalToOctal(2);
decimalToOctal(8);
decimalToOctal(65);
decimalToOctal(216);
decimalToOctal(512);