メイン radix.html   Last modified: Sep 01, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=EUC-JP">
<link rel="shortcut icon" href="../favicon.ico">
<title>JavaScript</title>

<script language="JavaScript">
<!--
function calc2(ip, fp, base)
{
  var digit = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")
  var result, t1, i
  var a = new Array()
  result = ""
  for (i = 0; ; i++) {
    a[i] = digit[ip % base]
    ip = Math.floor(ip/base)
    if (ip == 0) {
      break
    }
  }
  for (; i >= 0; i--) {
    result += a[i]
  }
  if (fp != 0) {
    result += "."
    for (i = 1; i <= 36/(Math.log(base)/Math.log(2)); i++) {
      t1 = Math.floor(fp*base)
      result += digit[t1]
      fp = fp*base-t1
      if (fp == 0) {
        break
      }
    }
  }
  return result+(fp != 0 ? " …" : "")
}

function calc(form)
{
  var n, ip, fp
  form.result1.value = form.result2.value = ""
  if (isNaN(n = parseFloat(form.data1.value)) || n < 0) {
    form.result1.value = form.result2.value  = form.result3.value = "計算できません(入力数値が変です)"
    return
  }
  ip = parseInt(form.data1.value)
  fp = n-ip
  form.result1.value = calc2(ip, fp, 2)
  form.result2.value = calc2(ip, fp, 8)
  form.result3.value = calc2(ip, fp, 16)
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<font size="+2"><b>基数変換(10進数を2進数,8進数,16進数で表現する)</b></font> <a  href="src/radix.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a>     Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>

<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>

<p>
10進数<input name="data1" value="128" size=20><p>
<input type="button" name="calcurate" value="計算開始" onClick="calc(this.form)">  <input type="button" name="clear" value="入力欄クリア" onClick="this.form.data1.value=''">  <input type="button" name="clear" value="出力欄クリア" onClick="this.form.result1.value=this.form.result2.value=this.form.result3.value=''"><p>

<table border=0>
<tr>
<td align=right>2進数表現</td><td><input name="result1" value="" size=50></td>
</tr>
<tr>
<td align=right>8進数表現</td><td><input name="result2" value="" size=50></td>
</tr>
<tr>
<td align=right>16進数表現</td><td><input name="result3" value="" size=50></td>
</tr>
</table>
<p>
結果に「…」が付いている場合は循環小数です。
</form>

<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../Hanasi/Algo/base.html">計算法の解説</a><br>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <A HREF="javascript:history.go(-1)">直前のページへ戻る</A>  <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../mail.html">E-mail to Shigenobu AOKI</a>
<p><center><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh"></center>
</body>
</html>


・ 直前のページへ戻る  ・ E-mail to Shigenobu AOKI

Made with Macintosh