Skip to content

Commit a4511d2

Browse files
authored
Merge pull request TheAlgorithms#327 from VishnuPothan/master
Added Oct to Decimal conversion
2 parents 34a1eb2 + 4934ee3 commit a4511d2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Conversions/OctToDecimal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function octalToDecimal (num) {
2+
let dec = 0
3+
let base = 1
4+
while (num > 0) {
5+
const r = num % 10
6+
num = Math.floor(num / 10)
7+
dec = dec + (r * base)
8+
base = base * 8
9+
}
10+
return dec
11+
}
12+
13+
// test cases
14+
console.log(octalToDecimal(56) === 46)
15+
console.log(octalToDecimal(2365) === 1269)

0 commit comments

Comments
 (0)