Tampilan :
Coding :
<html>
<head>
<head>
<title>Desimal ke Oktal</title>
</head>
<body>
</head>
<body>
<script type="text/javascript">
function konversi(){
dec = document.getElementById("awal").value;
but = document.getElementById("kon");
okt = document.getElementById("akhir");
des = parseInt(dec);
oct = parseInt(okt.value);
var x = des;
var z;
var oktal ="";
while (x > 8)
{
z = x % 8;
x = (x-z) / 8;
oktal = z + oktal;
}
if(x>=0)
{
z = x % 8;
x = x / 8;
oktal = z + oktal;
}
okt.value = oktal;
}
</script>
<form>
<input type="text" id="awal">
<input type="button" value="konversi" id="kon" onclick="konversi()">
<input type="text" id="akhir">
</form>
</body>
</html>
03.58 |
Category:
JavaScript
|
0
komentar
Comments (0)