-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02 Conversao Numeros.html
More file actions
46 lines (37 loc) · 1.38 KB
/
02 Conversao Numeros.html
File metadata and controls
46 lines (37 loc) · 1.38 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>02 Conversao Numeros</title>
</head>
<body>
Valor Decimal: <input id="dec"/>
<button id="Conversao" onclick="converter()">Converter</button>
<p id="bin"><p id="erro">
<p id="oct">
<p id="hex">
</body>
<script>
function converter(){
document.getElementById("erro").innerHTML = ''
document.getElementById("bin").innerHTML = ''
document.getElementById("oct").innerHTML = ''
document.getElementById("hex").innerHTML = ''
dec = document.getElementById("dec").value
dec = dec.replace(',', '.')
decFloat = parseFloat(dec)
bin = decFloat.toString(2)
oct = decFloat.toString(8)
hex = decFloat.toString(16)
if (!isNaN(bin) || !isNaN(oct) || !isNaN(hex)){
document.getElementById("bin").innerHTML = `Valor Bin: ${bin}`
document.getElementById("oct").innerHTML = `Valor Oct: ${oct}`
document.getElementById("hex").innerHTML = `Valor Hex: ${hex.toUpperCase()}`
}else {
document.getElementById("erro").innerHTML = 'Ops! Ocorreu um erro durante a conversão, tente novamente digitando somente números'
}
}
</script>
</html>