mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
Added Implementation of Decimal to Octal
This commit is contained in:
15
Conversions/DecimalToOctal.js
Normal file
15
Conversions/DecimalToOctal.js
Normal 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);
|
Reference in New Issue
Block a user