Skip to content

Commit 42013f8

Browse files
authored
Merge pull request vJechsmayr#53 from priyanshu2510/master
binary to decimal added
2 parents f7b676a + 6dfd5d4 commit 42013f8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function binarytodecimal(b) {
2+
return parseInt((b + '')
3+
.replace(/[^01]/gi, ''), 2);
4+
}
5+
console.log(binarytodecimal('101010'));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function(){
2+
3+
var ConvertBase = function (num) {
4+
return {
5+
from : function (baseFrom) {
6+
return {
7+
to : function (baseTo) {
8+
return parseInt(num, baseFrom).toString(baseTo);
9+
}
10+
};
11+
}
12+
};
13+
};
14+
ConvertBase.hex2dec = function (num) {
15+
return ConvertBase(num).from(16).to(10);
16+
};
17+
18+
this.ConvertBase = ConvertBase;
19+
20+
})(this);
21+
console.log(ConvertBase.hex2dec('f8'));
22+

0 commit comments

Comments
 (0)