From 446f88b189bdad556887d347501defe46abc89eb Mon Sep 17 00:00:00 2001 From: Vishnu Date: Thu, 1 Oct 2020 16:42:37 +0530 Subject: [PATCH] Added Oct to Decimal conversion --- Conversions/OctToDecimal.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Conversions/OctToDecimal.js 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