-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConv.html
More file actions
303 lines (242 loc) · 9.49 KB
/
Copy pathConv.html
File metadata and controls
303 lines (242 loc) · 9.49 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!DOCTYPE html>
<html>
<head>
<title>Number System Converter</title>
<meta charset="UTF-8">
<meta name="description" content="Conversion Of Number Systems">
<meta name="keywords" content="HTML, CSS, Python, Number System Conversion, Converter">
<meta name="author" content="VIT">
<meta http-equiv="refresh" content="600">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body, html {
height: 100%;
margin: 0;
}
body {
font-family: 'Arial', sans-serif;
background-image: url(https://images.rawpixel.com/image_800/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIzLTA3L2pvYjE0NDgtYmFja2dyb3VuZC0wNGEteF8xLmpwZw.jpg);
text-align: center;
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
#container {
background-color: rgba(255, 255, 255, 0.9);
border-radius: 8px;
padding: 40px;
margin: 5% auto;
width: 80%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
font-family: 'Verdana', Geneva, Tahoma, sans-serif;
font-weight: 700;
font-size: 35px;
margin:10px;
}
input {
padding: 10px;
margin: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
select {
padding: 10px;
font-size: 16px;
}
div {
margin-top: 20px;
font-size: 18px;
}
.menu-container{
display: flex;
color: white;
background-color: black;
margin: 0%;
justify-content:space-around;
height: fit-content;
}
li,a{
place-content: center;
color: white;
list-style: none;
text-decoration: none;
font-size: 25px;
}
</style>
</head>
<body>
<div class="menu-container">
<h1><a href="index.html"> <h1>NUMBER SYSTEM</h1></a></h1>
<li><a href="index.html">Home</a></li>
<li><a href="Info.html">Info</a></li>
<li><a href="Conv.html">Conversion</a></li>
</div>
<br>
<h1 style="display:inline-block"> BINARY Number System Converter</h1><br>
<input type="text" id="binaryInput1" placeholder="Enter binary number" /><br>
<br>
<label for="conversionType1">Convert to:</label>
<select id="conversionType1">
<option value="decimal1">Decimal</option>
<option value="hexadecimal1">Hexadecimal</option>
<option value="octal1">Octal</option>
</select>
<br><br>
<button onclick="convert1()">Convert</button>
<div id="result1"></div>
<script>
function convert1() {
var binaryInput1 = document.getElementById("binaryInput1").value;
var conversionType1 = document.getElementById("conversionType1").value;
if (!/^[01]+$/.test(binaryInput1)) {
document.getElementById("result1").innerHTML = "Invalid binary input";
return;
}
var decimal1 = parseInt(binaryInput1, 2);
switch (conversionType1) {
case "decimal1":
document.getElementById("result1").innerHTML = "Decimal: " + decimal1;
break;
case "hexadecimal1":
var hexadecimal1 = decimal1.toString(16).toUpperCase();
document.getElementById("result1").innerHTML = "Hexadecimal: " + hexadecimal1;
break;
case "octal1":
var octal1 = decimal1.toString(8);
document.getElementById("result1").innerHTML = "Octal: " + octal1;
break;
default:
document.getElementById("result1").innerHTML = "Invalid conversion type";
break;
}
}
</script>
<h1 style="display:inline-block"> DECIMAL Number System Converter </h1><br>
<input type="text" id="decimalInput" placeholder="Enter decimal number" /><br>
<br>
<label for="conversionType">Convert to:</label>
<select id="conversionType">
<option value="binary">Binary</option>
<option value="hexadecimal">Hexadecimal</option>
<option value="octal">Octal</option>
</select>
<br><br>
<button onclick="convert()">Convert</button>
<div id="result"></div>
<script>
function convert() {
var decimalInput = document.getElementById("decimalInput").value;
var conversionType = document.getElementById("conversionType").value;
if (!/^\d+$/.test(decimalInput)) {
document.getElementById("result").innerHTML = "Invalid decimal input";
return;
}
var decimal = parseInt(decimalInput, 10);
switch (conversionType) {
case "binary":
var binary = decimal.toString(2);
document.getElementById("result").innerHTML = "Binary: " + binary;
break;
case "hexadecimal":
var hexadecimal = decimal.toString(16).toUpperCase();
document.getElementById("result").innerHTML = "Hexadecimal: " + hexadecimal;
break;
case "octal":
var octal = decimal.toString(8);
document.getElementById("result").innerHTML = "Octal: " + octal;
break;
default:
document.getElementById("result").innerHTML = "Invalid conversion type";
break;
}
}
</script>
<h1 style="display:inline-block"> HEXADECIMAL Number System Converter </h1><br>
<input type="text" id="hexadecimalInput2" placeholder="Enter hexadecimal number" /><br>
<br>
<label for="conversionType2">Convert to:</label>
<select id="conversionType2">
<option value="binary2">Binary</option>
<option value="decimal2">Decimal</option>
<option value="octal2">Octal</option>
</select>
<br><br>
<button onclick="convert2()">Convert</button>
<div id="result2"></div>
<script>
function convert2() {
var hexadecimalInput2 = document.getElementById("hexadecimalInput2").value;
var conversionType2 = document.getElementById("conversionType2").value;
if (!/^[0-9A-Fa-f]+$/.test(hexadecimalInput2)) {
document.getElementById("result2").innerHTML = "Invalid hexadecimal input";
return;
}
// Convert hexadecimal to decimal
var decimal2 = parseInt(hexadecimalInput2, 16);
switch (conversionType2) {
case "binary2":
var binary2 = decimal2.toString(2);
document.getElementById("result2").innerHTML = "Binary: " + binary2;
break;
case "decimal2":
document.getElementById("result2").innerHTML = "Decimal: " + decimal2;
break;
case "octal2":
var octal2 = decimal2.toString(8);
document.getElementById("result2").innerHTML = "Octal: " + octal2;
break;
default:
document.getElementById("result2").innerHTML = "Invalid conversion type";
break;
}
}
</script>
<h1 style="display:inline-block"> OCTAL Number System Converter </h1><br>
<input type="text" id="octalInput3" placeholder="Enter octal number" /><br>
<br>
<label for="conversionType3">Convert to:</label>
<select id="conversionType3">
<option value="binary3">Binary</option>
<option value="decimal3">Decimal</option>
<option value="hexadecimal3">Hexadecimal</option>
</select>
<br><br>
<button onclick="convert3()">Convert</button>
<div id="result3"></div><br><br><br>
<script>
function convert3() {
var octalInput3 = document.getElementById("octalInput3").value;
var conversionType3 = document.getElementById("conversionType3").value;
if (!/^[0-7]+$/.test(octalInput3)) {
document.getElementById("result3").innerHTML = "Invalid octal input";
return;}
// Convert octal to decimal
var decimal3 = parseInt(octalInput3, 8);
switch (conversionType3) {
case "binary3":
var binary3 = decimal3.toString(2);
document.getElementById("result3").innerHTML = "Binary: " + binary3;
break;
case "decimal3":
document.getElementById("result3").innerHTML = "Decimal: " + decimal3;
break;
case "hexadecimal3":
var hexadecimal3 = decimal3.toString(16).toUpperCase();
document.getElementById("result3").innerHTML = "Hexadecimal: " + hexadecimal3;
break;
default:
document.getElementById("result3").innerHTML = "Invalid conversion type";
break;
}
}
</script>
</body>
</html>