Formulare Web ,CSS,Javascript


TRECE UN NUMAR IN BAZA 2 din baza 10



Vom scrie codul de mai jos in NOTEPAD si il salvam ALL Files si intre paranteze scriem :"baza2.html"

<style>
form {
  border-radius: 25px;
    border: 2px solid #831bc1;
    padding: 20px;
    width: 200px;
    height: 150px;
}
body {
   border-radius: 25px;
    border: 2px solid #73AD21;
    padding: 20px;
    width: 800px;
    height: 800px; }
hr { width:200px;height:20px;color:yellow;}
</style>

<body BGCOLOR="#99cc00">
<marquee>Transforma din baza 2 in baza 10 </marquee>
<H1>Scrie n si apasa pe buton  </H1>

<script language="javascript">
function baza2()
{
  var n,n1,aux,nr,  s, i;

//n e numarul , nr e rezultatul , 2-baza, n1-catul la imp la 2
//aux-e nr scris invers
n=eval(document.getElementById("numar").value);
document.writeln(n," este numarul introdus si in baza 2 este<hr><br> ");
n1=n;s="";
while(n>0){ document.writeln("o cifra este  ",n%2,"<br>");
s=String(n%2)+s;
n=Math.floor(n/2);
}
alert(String(n1)+" scris in baza 2 este "+s);
}
</script>
<form>
<p>
<font color = #60605e><label> dati n </label>
<input type="text" value="0"id="numar">
</font>
</p>
<input type = "button" value = "Transforma in baza 2 " Onclick="baza2(this)">
<hr>
</form>
</body>



Un comentariu: