diff --git a/Conversions/OctToDecimal.js b/Conversions/OctToDecimal.js new file mode 100644 index 000000000..b2b3a4aa0 --- /dev/null +++ b/Conversions/OctToDecimal.js @@ -0,0 +1,15 @@ +function octalToDecimal (num) { + let dec = 0 + let base = 1 + while (num > 0) { + const r = num % 10 + num = Math.floor(num / 10) + dec = dec + (r * base) + base = base * 8 + } + return dec + } + +// test cases +console.log(octalToDecimal(56) === 46) +console.log(octalToDecimal(2365) === 1269) \ No newline at end of file