-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (30 loc) · 849 Bytes
/
index.js
File metadata and controls
38 lines (30 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var BaseConvert = {
converter: function(number) {
this.fromBase = function(baseFrom) {
this.toBase = function(baseTo) {
return parseInt(number, baseFrom).toString(baseTo);
};
return this;
};
return this;
},
dec2hex: function(number) {
return this.converter(number).fromBase(10).toBase(16);
},
hex2dec: function(number) {
return this.converter(number).fromBase(16).toBase(10);
},
bin2dec: function(number) {
return this.converter(number).fromBase(2).toBase(10);
},
dec2bin: function(number) {
return this.converter(number).fromBase(10).toBase(2);
},
bin2hex: function(number) {
return this.converter(number).fromBase(2).toBase(16);
},
hex2bin: function(number) {
return this.converter(number).fromBase(16).toBase(2);
}
};
module.exports = BaseConvert;