-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (28 loc) · 897 Bytes
/
app.js
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
function codeConversion(){
const inputValue = document.getElementById('input-value').value;
const inputValueNumber = parseInt (inputValue);
// Code conversion
dec_to_bho = function (n, base) {
if (n < 0) {
n = 0xFFFFFFFF + n + 1;
}
switch (base) {
case 'B':
return parseInt(n, 10).toString(2);
break;
case 'H':
return parseInt(n, 10).toString(16);
break;
case 'O':
return parseInt(n, 10).toString(8);
break;
default:
return ("Wrong input.........");
}
}
document.getElementById('show-result').innerHTML = `
<h4>Binary: ( ${dec_to_bho(inputValueNumber, 'B')} ) <sub>2</sub> </h4>
<h4>Octal : ( ${dec_to_bho(inputValueNumber, 'O')} ) <sub>8</sub> </h4>
<h4>Hexadicimal: ( ${dec_to_bho(inputValueNumber, 'H')} ) <sub>16</sub> </h4>
`;
}