JAVASCRIPT Convertisseur Binaire/Hexadécimal/Décimal
Table des matières
Voici un petit bout de code HTML et Javascript pour convertir rapidement et facilement en hexadécimal, binaire, décimal.
Introduction
Voici un petit bout de code HTML et Javascript pour convertir rapidement et facilement en hexadécimal, binaire, décimal.
Programme
Le code
Code JAVASCRIPT :
function xdecimal() { decimal = document.getElementById("decimal"); hexadecimal = document.getElementById("hexadecimal"); binaire = document.getElementById("binaire"); hexadecimal.value = (decimal.value-0).toString(16); binaire.value = (decimal.value-0).toString(2); } function xhexadecimal() { decimal = document.getElementById("decimal"); hexadecimal = document.getElementById("hexadecimal"); binaire = document.getElementById("binaire"); decimal.value = parseInt(hexadecimal.value,16); binaire.value = (parseInt(hexadecimal.value,16)).toString(2); } function xbinaire() { decimal = document.getElementById("decimal"); hexadecimal = document.getElementById("hexadecimal"); binaire = document.getElementById("binaire"); decimal.value = parseInt(binaire.value,2); hexadecimal.value = (parseInt(binaire.value,2)).toString(16); }
Code CSS :
input[type='text'] { text-transform:uppercase; }
Code HTML :
<form action=""> <p><label for="decimal">Décimal : </label> <input type="text" id="decimal" name="decimal" > <input type="button" name="submit1" value="⇢" onClick="xdecimal();"></p> <p><label for="hexadecimal">Hexadécimal : </label> <input type="text" id="hexadecimal" name="hexadecimal"> <input type="button" name="submit2" value="⇢" onClick="xhexadecimal();"></p> <p><label for="hexadecimal">Binaire : </label> <input type="text" id="binaire" name="binaire"> <input type="button" name="submit3" value="⇢" onClick="xbinaire();"></p> </form>