forked from kokonior/HTML-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumbering System Calculator.html
More file actions
190 lines (134 loc) · 6.06 KB
/
Numbering System Calculator.html
File metadata and controls
190 lines (134 loc) · 6.06 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<title>Let's Learn to Convert Numbering System</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<script>
function converter(n) {
//first drop down
var numSystemOne = document.getElementById('numSystemOne').value;
//second drop down
var numSystemTwo = document.getElementById('numSystemTwo').value;
//input text
var number = document.getElementById('number').value;
var num;
if ( number == "" || numSystemOne == "" || numSystemTwo == "" ) {
alert("Please select or enter value");
return false;
}
else{
//decimal->divison method
if (numSystemOne== "Decimal") {
if (numSystemTwo == "Binary") {
num=parseInt(number + '', 10).toString(2);
}
else if (numSystemTwo == "Octal") {
num=parseInt(number + '', 10).toString(8);
}
else if(numSystemTwo == "Hexadecimal") {
num=parseInt(number + '', 10).toString(16);
}
else{
num=number;
}
}
//decimal<-multification method
else if (numSystemTwo== "Decimal") {
if (numSystemOne == "Binary") {
num=parseInt(number + '', 2).toString(10);
}
else if (numSystemOne == "Octal") {
num=parseInt(number + '', 8).toString(10);
}
else if(numSystemOne == "Hexadecimal") {
num=parseInt(number + '', 16).toString(10);
}
else{
num=number;
}
}
else if (numSystemOne == "Binary") {
if (numSystemTwo == "Octal") {
num=parseInt(number + '', 2).toString(8);
}
else if (numSystemTwo == "Hexadecimal") {
num=parseInt(number + '', 2).toString(16);
}
else{
num=number;
}
}
else if (numSystemOne == "Octal") {
if (numSystemTwo == "Binary") {
num=parseInt(number + '', 8).toString(2);
}
else if (numSystemTwo == "Hexadecimal") {
num=parseInt(number + '', 8).toString(16);
}
else{
num=number;
}
}
else if (numSystemOne == "Hexadecimal") {
if (numSystemTwo == "Binary") {
num=parseInt(number + '', 16).toString(2);
}
else if (numSystemTwo == "Octal") {
num=parseInt(number + '',16).toString(8);
}
else{
num=number;
}
}
alert(num);
return true;
}
}
</script>
</head>
<body>
<div class="row row-content alert-dark" id="con">
<div class="card card-container col-sm-12 col-12">
<h1 class="card-header"> <i class="fa fa-calculator fa-lg" aria-hidden="true"></i> Number System Converter</h1>
<!--converter-->
<form class="card-body" action="" name="myForm" onsubmit="return converter(this);" method="post">
<div class="row form-group">
<div class="col-6 col-sm-2">Select Number System</div>
<select class="col-6 col-sm-2 custom-select" name="numSystemOne" id="numSystemOne">
<option value="Decimal" id="decimalO">Decimal</option>
<option value="Binary" id="binaryO">Binary</option>
<option value="Octal" id="octallO">Octal</option>
<option value="Hexadecimal" id="hexadecimalO">Hexadecimal</option>
</select>
<h5 class="col-6 col-sm-2 offset-sm-1 offset-3 mt-2 border-2 p-1 bg-dark text-white rounded-circle mb-3"><center>Convert to<i class="fa fa-caret-right fa-lg d-none d-sm-block" aria-hidden="true"></i><i class="fa fa-caret-down fa-lg d-block d-sm-none" aria-hidden="true"></i></center></h5>
<div class="col-6 col-sm-2">Select Number System</div>
<select class="col-6 col-sm-2 custom-select" name="numSystemTwo" id="numSystemTwo">
<option value="Decimal" id="decimalT">Decimal</option>
<option value="Binary" id="binarylT">Binary</option>
<option value="Octal" id="octalT">Octal</option>
<option value="Hexadecimal" id="hexadecimalT">Hexadecimal</option>
</select>
</div><br>
<div class="row form-group">
<div class="col-6 col-sm-2 col-sm-2">Enter Value</div>
<input class="col-6 col-sm-2 form-control" id="number" type="text" name="number">
<div class="col-12 col-sm-2 offset-sm-1 mt-3 mb-3"> </div>
<!--<div class="col-6 col-sm-2 col-sm-2" id="answer">Answer</div>
<div class="col-6 col-sm-2" id="answertext"></div><br>-->
</div>
<div class="row">
<input type="submit" class="btn btn-primary col-sm-4 col-12 offset-sm-4 form-control " name="convert" id="convert" value="Convert">
</div>
</form>
</div>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>