»
AnglaisFranaisVietnamien

Imprimer - Base Converter - JavaScriptBank.com

Version complte: jsB@nk » Calcul » Équivalent » Base Converter
URL: http://www.javascriptbank.com/a-base-converter.html

Base Converter © JavaScriptBank.comUne base de convertisseur. Il suffit de taper un nombre positif en vigueur dans l'une des cases et cliquez sur l'extérieur de la boîte. Le équivalent apparaissent dans les autres cases.

Version complte: jsB@nk » Calcul » Équivalent » Base Converter
URL: http://www.javascriptbank.com/a-base-converter.html



JavaScript
<SCRIPT language=JavaScript><!-- for wise eyes onlyvar hex;function MakeArray(){    this.length = 16;    return this;}function Populate(){    hex = new MakeArray();    hex[1] = "0";        hex[2] = "1";        hex[3] = "2";        hex[4] = "3";        hex[5] = "4";        hex[6] = "5";        hex[7] = "6";        hex[8] = "7";        hex[9] = "8";        hex[10] = "9";        hex[11] = "A";        hex[12] = "B";        hex[13] = "C";        hex[14] = "D";        hex[15] = "E";        hex[16] = "F";    }// function DecimaltoAnother(N, radix)// // return representation of a number N// in the system based on radix //function DecimaltoAnother(N, radix){    s = "";    A = N;    while (A >= radix)    {        B = A % radix;        A = Math.floor(A / radix);        s += hex[B+1];    }        s += hex[A+1];    return Transpose(s);}// function Transpose(s)//// return a string written from right to left//function Transpose(s){    N = s.length;    t = "";    for (i = 0; i < N; i++)        t = t + s.substring(N-i-1, N-i);    s = t;    return s;}function EvalB(form){    if (form.b.value.length != 0)        M = parseInt(form.b.value, 2);    else        M = 0;    form.t.value = DecimaltoAnother(M, 3);    form.q.value = DecimaltoAnother(M, 5);    form.o.value = DecimaltoAnother(M, 8);    form.h.value = DecimaltoAnother(M, 16);    form.d.value = M;}function EvalT(form){    if (form.t.value.length != 0)        M = parseInt(form.t.value, 3);    else        M = 0;    form.b.value = DecimaltoAnother(M, 2);    form.q.value = DecimaltoAnother(M, 5);    form.o.value = DecimaltoAnother(M, 8);    form.h.value = DecimaltoAnother(M, 16);    form.d.value = M;}function EvalQ(form){    if (form.q.value.length != 0)        M = parseInt(form.q.value, 5);    else        M = 0;    form.b.value = DecimaltoAnother(M, 2);    form.t.value = DecimaltoAnother(M, 3);    form.o.value = DecimaltoAnother(M, 8);    form.h.value = DecimaltoAnother(M, 16);    form.d.value = M;}function EvalO(form){    if (form.o.value.length != 0)        M = parseInt(form.o.value, 8);    else        M = 0;    form.b.value = DecimaltoAnother(M, 2);    form.t.value = DecimaltoAnother(M, 3);    form.q.value = DecimaltoAnother(M, 5);    form.h.value = DecimaltoAnother(M, 16);    form.d.value = M;}function EvalH(form){    if (form.h.value.length != 0)        M = parseInt(form.h.value, 16);    else        M = 0;    form.b.value = DecimaltoAnother(M, 2);    form.t.value = DecimaltoAnother(M, 3);    form.q.value = DecimaltoAnother(M, 5);    form.o.value = DecimaltoAnother(M, 8);    form.d.value = M;}function EvalD(form){    if (form.d.value.length != 0)        M = parseInt(form.d.value, 10);    else        M = 0;    form.b.value = DecimaltoAnother(M, 2);    form.t.value = DecimaltoAnother(M, 3);    form.q.value = DecimaltoAnother(M, 5);    form.o.value = DecimaltoAnother(M, 8);    form.h.value = DecimaltoAnother(M, 16);}//-- done hiding from old browsers --></SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM method=post><TABLE cellSpacing=3 cellPadding=3 align=center border=0>  <TBODY>  <TR>    <TD align=right>      <P>Binary (Base 2):</P></TD>    <TD><INPUT onchange=EvalB(form) size=27 value=0 name=b></TD><TD><code>Ex: 101, 101,...</code></TD></TR>  <TR>    <TD align=right>Ternary (Base 3):</TD>    <TD><INPUT onchange=EvalT(form) size=21 value=0 name=t></TD><TD><code>Ex: 102, 201,...</code></TD></TR>  <TR>    <TD align=right>Quintal (Base 5):</TD>    <TD><INPUT onchange=EvalQ(form) size=16 value=0 name=q></TD><TD><code>Ex: 123, 104,...</code></TD></TR>  <TR>    <TD align=right>Octal (Base 8):</TD>    <TD><INPUT onchange=EvalO(form) size=12 value=0 name=o></TD><TD><code>Ex: 1207, 12036,...</code></TD></TR>  <TR>    <TD align=right>Decimal (Base 10):</TD>    <TD><INPUT onchange=EvalD(form) size=11 value=0 name=d></TD><TD><code>Ex: 12389,...</code></TD></TR>  <TR>    <TD align=right>Hexadecimal (Base 16):</TD>    <TD><INPUT onchange=EvalH(form) size=8 value=0 name=h> </TD><TD><code>Ex: 12AB,...</code></TR></TBODY></TABLE></FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->