⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieee-754 floating-point conversion from floating-point to hexadecimal.mht

📁 IEEE-754 Floating-Point Conversion From Decimal Floating-Point To 32-bit and 64-bit Hexadecimal Re
💻 MHT
📖 第 1 页 / 共 3 页
字号:
  numerals =3D new String()=0A=
  tempstr =3D new String()=0A=
  expstr =3D new String()=0A=
  signstr =3D new String()=0A=
=0A=
  var locE, stop, expnum, locDP, start, MSD, MSDfound, index, expdelta, =
digits=0A=
  var number=0A=
=0A=
  numerals =3D "0123456789";=0A=
=0A=
  tempstr =3D input.toUpperCase()=0A=
=0A=
  locE =3D tempstr.indexOf("E");=0A=
  if (locE !=3D -1)=0A=
  {=0A=
    stop =3D locE=0A=
    expstr =3D input.substring(locE + 1, input.length)=0A=
    expnum =3D expstr * 1=0A=
  }=0A=
  else=0A=
  {=0A=
    stop =3D input.length=0A=
    expnum =3D 0=0A=
  }=0A=
=0A=
  if (input.indexOf(".") =3D=3D -1)=0A=
  {=0A=
    tempstr =3D input.substring(0, stop)=0A=
    tempstr +=3D "."=0A=
    if (input.length !=3D stop)=0A=
      tempstr +=3D input.substring(locE, input.length)=0A=
=0A=
    input =3D tempstr=0A=
=0A=
    locE =3D locE + 1=0A=
    stop =3D stop + 1=0A=
  }=0A=
=0A=
  locDP =3D input.indexOf(".");=0A=
=0A=
  start =3D 0=0A=
  if (input.charAt(start) =3D=3D "-")=0A=
  {=0A=
    start++=0A=
    signstr =3D "-"=0A=
  }=0A=
  else=0A=
    signstr =3D ""=0A=
=0A=
  MSD =3D start=0A=
  MSDfound =3D false=0A=
  while ((MSD < stop) && !MSDfound)=0A=
  {=0A=
    index =3D 1=0A=
    while (index < numerals.length)=0A=
    {=0A=
      if (input.charAt(MSD) =3D=3D numerals.charAt(index))=0A=
      {=0A=
        MSDfound =3D true=0A=
        break=0A=
      }=0A=
      index++=0A=
    }=0A=
    MSD++=0A=
  }=0A=
  MSD--=0A=
=0A=
  if (MSDfound)=0A=
  {=0A=
    expdelta =3D locDP - MSD=0A=
    if (expdelta > 0)=0A=
      expdelta =3D expdelta - 1=0A=
=0A=
    expnum =3D expnum + expdelta=0A=
=0A=
    expstr =3D "e" + expnum=0A=
  }=0A=
  else  //No significant digits found, value is zero=0A=
    MSD =3D start=0A=
=0A=
  digits =3D stop - MSD=0A=
=0A=
  tempstr =3D input.substring(MSD, stop)=0A=
=0A=
  if (tempstr.indexOf(".") !=3D -1)=0A=
    digits =3D digits - 1=0A=
=0A=
  number =3D digits=0A=
  if (precision < digits)=0A=
    number =3D precision=0A=
=0A=
  tempstr =3D input.substring(MSD, MSD + number + 1)=0A=
=0A=
  if ( (MSD !=3D start) || (tempstr.indexOf(".") =3D=3D -1) )=0A=
  {=0A=
    result =3D signstr=0A=
    result +=3D input.substring(MSD, MSD + 1)=0A=
    result +=3D "."=0A=
    result +=3D input.substring(MSD + 1, MSD + number)=0A=
=0A=
    while (digits < precision)=0A=
    {=0A=
      result +=3D "0"=0A=
      digits +=3D 1=0A=
    }=0A=
=0A=
    result +=3D expstr=0A=
  }=0A=
  else=0A=
  {=0A=
    result =3D input.substring(0, start + number + 1)=0A=
=0A=
    while (digits < precision)=0A=
    {=0A=
      result +=3D "0"=0A=
      digits +=3D 1=0A=
    }=0A=
=0A=
    if (input.length !=3D stop)=0A=
      result +=3D input.substring(locE, input.length)=0A=
  }=0A=
=0A=
  return result;=0A=
}=0A=
=0A=
function numCutOff(input, precision)=0A=
{=0A=
  result =3D new String()=0A=
  tempstr =3D new String()=0A=
=0A=
  var temp =3D input;=0A=
  if(temp < 1)=0A=
    temp +=3D 1;=0A=
=0A=
  tempstr =3D "" + temp;=0A=
=0A=
  tempstr =3D numStrClipOff(tempstr, precision);=0A=
=0A=
  if(temp =3D=3D input)=0A=
    result =3D tempstr.substring(0, 1);=0A=
  else=0A=
    result =3D "0";=0A=
=0A=
  result +=3D tempstr.substring(1, tempstr.length);=0A=
=0A=
  return result;=0A=
}=0A=
=0A=
function Convert2Dec()=0A=
{=0A=
  output =3D new String()=0A=
=0A=
  var s, i, dp, val, hid, temp, decValue, power=0A=
=0A=
  with (Math)=0A=
  {=0A=
  if (this.Size =3D=3D 32) s =3D 9=0A=
  else s =3D 12=0A=
=0A=
  if ((this.BinaryPower < this.MinExp) || (this.BinaryPower > =
this.MaxExp))=0A=
  {=0A=
    dp =3D 0=0A=
    val =3D 0=0A=
  }=0A=
  else=0A=
  {=0A=
    dp =3D - 1=0A=
    val =3D 1=0A=
  }=0A=
=0A=
  for (i =3D s; i < this.Size; i++)=0A=
    val +=3D parseInt(this.Result[i])*pow(2, dp + s - i)=0A=
=0A=
  decValue =3D val * pow(2, this.BinaryPower)=0A=
=0A=
  if (this.Size =3D=3D 32)=0A=
  {=0A=
    s =3D 8=0A=
    if (val > 0)=0A=
    {=0A=
      power =3D floor( log(decValue) / LN10 )=0A=
      decValue +=3D 0.5 * pow(10, power - s + 1)=0A=
      val +=3D 5E-8=0A=
    }=0A=
  }=0A=
  else s =3D 17=0A=
=0A=
  if (this.Result[0] =3D=3D 1) decValue =3D - decValue=0A=
=0A=
  //the system refuses to display negative "0"s with a minus sign=0A=
  this.DecValue =3D "" + decValue=0A=
  if ((this.DecValue =3D=3D "0") && (this.Result[0] =3D=3D 1))=0A=
    this.DecValue =3D "-" + this.DecValue=0A=
=0A=
  this.DecValue =3D numStrClipOff(this.DecValue, s)=0A=
=0A=
  output =3D numCutOff(val, s)=0A=
=0A=
  }=0A=
  return output=0A=
}=0A=
=0A=
//object construction function=0A=
function ieee (Size){=0A=
=0A=
  this.Size =3D Size=0A=
  this.BinaryPower =3D 0=0A=
  this.DecValue =3D ""=0A=
  this.DispStr =3D ""=0A=
  this.Convert2Bin =3D Convert2Bin   //convert input to bin.=0A=
  this.Convert2Hex =3D Convert2Hex   //convert bin. to hex.=0A=
  this.Convert2Dec =3D Convert2Dec   //convert bin. significand to dec.=0A=
  this.Dec2Bin =3D Dec2Bin           //convert dec. to bin.=0A=
  this.StatCond =3D "normal"=0A=
  this.StatCond64 =3D "normal"=0A=
  this.BinString =3D ""=0A=
  // 1 (carry bit) + 1023 + 1 + 1022 + 53 + 2 (round bits)=0A=
  this.BinVal =3D new Array(2102)    //Binary Representation=0A=
  if (Size =3D=3D 32){=0A=
    this.ExpBias =3D 127=0A=
    this.MaxExp =3D 127=0A=
    this.MinExp =3D -126=0A=
    this.MinUnnormExp =3D -149=0A=
    this.Result =3D new Array(32)=0A=
  }=0A=
  else if (Size =3D=3D 64){=0A=
    this.ExpBias =3D 1023=0A=
    this.MaxExp =3D 1023=0A=
    this.MinExp =3D -1022=0A=
    this.MinUnnormExp =3D -1074=0A=
    this.Result =3D new Array(64)=0A=
  }=0A=
=0A=
}=0A=
=0A=
function compute(obj, rounding){=0A=
/*=0A=
  in this javascript program, bit positions are numbered=0A=
  0 ~ 32/64 from left to right instead of right to left, the=0A=
  way the output is presented=0A=
*/=0A=
  ieee32 =3D new ieee(32)=0A=
  ieee64 =3D new ieee(64)=0A=
=0A=
  var input, index1, cnst=0A=
=0A=
  input =3D obj.input.value=0A=
  input =3D RemoveBlanks(input)=0A=
=0A=
  ieee64.Dec2Bin(input)=0A=
  ieee64.BinString =3D=0A=
    ieee64.Convert2Bin(ieee64.DispStr, ieee64.StatCond64, =
ieee64.Result[0],=0A=
                         ieee64.BinaryPower, false)=0A=
  obj.bin64_0.value =3D ieee64.BinString.substring(0, 1)=0A=
  obj.bin64_1.value =3D ieee64.BinString.substring(1, 12)=0A=
  if ((ieee64.BinaryPower < ieee64.MinExp) ||=0A=
      (ieee64.BinaryPower > ieee64.MaxExp))=0A=
  {=0A=
    obj.bin64_12.value =3D "  "=0A=
    obj.bin64_12.value +=3D ieee64.BinString.substring(12, 13)=0A=
    obj.bin64_12.value +=3D "."=0A=
    obj.bin64_12.value +=3D ieee64.BinString.substring(13, 64)=0A=
  }=0A=
  else=0A=
  {=0A=
    obj.bin64_12.value =3D "1 ."=0A=
    obj.bin64_12.value +=3D ieee64.BinString.substring(12, 64)=0A=
  }=0A=
  obj.stat64.value =3D ieee64.StatCond=0A=
  obj.binpwr64.value =3D ieee64.BinaryPower=0A=
  obj.binpwr64f.value =3D ieee64.BinaryPower + ieee64.ExpBias=0A=
  obj.dec64sig.value =3D ieee64.Convert2Dec()=0A=
  if (ieee64.DispStr !=3D "")=0A=
  {=0A=
    obj.dec64.value =3D ieee64.DispStr=0A=
    obj.dec64sig.value =3D ""=0A=
  }=0A=
  else=0A=
    obj.dec64.value =3D ieee64.DecValue=0A=
  obj.hex64.value =3D ieee64.Convert2Hex()=0A=
=0A=
    cnst =3D 2102         // 1 (carry bit) + 1023 + 1 + 1022 + 53 + 2 =
(round bits)=0A=
    for (index1 =3D 0; index1 < cnst; index1++)=0A=
      ieee32.BinVal[index1] =3D ieee64.BinVal[index1]=0A=
=0A=
  ieee32.BinString =3D=0A=
    ieee32.Convert2Bin(ieee64.DispStr, ieee64.StatCond64, =
ieee64.Result[0],=0A=
                         ieee64.BinaryPower, rounding)=0A=
  obj.bin32_0.value =3D ieee32.BinString.substring(0, 1)=0A=
  obj.bin32_1.value =3D ieee32.BinString.substring(1, 9)=0A=
  if ((ieee32.BinaryPower < ieee32.MinExp) ||=0A=
      (ieee32.BinaryPower > ieee32.MaxExp))=0A=
  {=0A=
    obj.bin32_9.value =3D "  "=0A=
    obj.bin32_9.value +=3D ieee32.BinString.substring(9, 10)=0A=
    obj.bin32_9.value +=3D "."=0A=
    obj.bin32_9.value +=3D ieee32.BinString.substring(10, 32)=0A=
  }=0A=
  else=0A=
  {=0A=
    obj.bin32_9.value =3D "1 ."=0A=
    obj.bin32_9.value +=3D ieee32.BinString.substring(9, 32)=0A=
  }=0A=
  obj.stat32.value =3D ieee32.StatCond=0A=
  obj.binpwr32.value =3D ieee32.BinaryPower=0A=
  obj.binpwr32f.value =3D ieee32.BinaryPower + ieee32.ExpBias=0A=
  obj.dec32sig.value =3D ieee32.Convert2Dec()=0A=
  if (ieee32.DispStr !=3D "")=0A=
  {=0A=
    obj.dec32.value =3D ieee32.DispStr=0A=
    obj.dec32sig.value =3D ""=0A=
  }=0A=
  else=0A=
    obj.dec32.value =3D ieee32.DecValue=0A=
  obj.hex32.value =3D ieee32.Convert2Hex()=0A=
=0A=
  if ((ieee64.DispStr !=3D "") && (ieee32.DispStr !=3D ""))=0A=
    obj.entered.value =3D ieee64.DispStr=0A=
  else=0A=
    obj.entered.value =3D input * 1.0=0A=
}=0A=
</SCRIPT>

<META content=3D"MSHTML 6.00.6000.16544" name=3DGENERATOR></HEAD>
<BODY text=3Dnavy bgColor=3Dlightblue><BASEFONT size=3D4>
<CENTER><FONT size=3D+2>IEEE-754 Floating-Point =
Conversion</FONT><BR><FONT=20
size=3D+1>From Decimal Floating-Point<BR>To 32-bit and 64-bit =
Hexadecimal=20
Representations<BR>Along with Their Binary Equivalents </FONT></CENTER>
<P></P>
<FORM>Enter a decimal floating-point number here,<BR>then click either =
the=20
<B>Rounded</B> or the <B>Not Rounded</B> button.<BR><BR><FONT =
size=3D-1>Decimal=20
Floating-Point: <INPUT size=3D25 name=3Dinput> <INPUT type=3Dreset =
value=3DClear><BR>
<HR width=3D"30%">

<CENTER><INPUT onclick=3D"compute(this.form, true)" type=3Dbutton =
value=3DRounded> <INPUT onclick=3D"compute(this.form, false)" =
type=3Dbutton value=3D"Not Rounded">=20
<BR></CENTER>
<HR width=3D"30%">
Rounding from floating-point to 32-bit representation uses the IEEE-754=20
round-to-nearest-value mode.<BR>
<HR>
<BR><FONT size=3D4>Results:<BR><BR>Decimal Value Entered: <FONT =
size=3D-1><INPUT=20
size=3D24 name=3Dentered></FONT><BR><BR><BR><U>Single precision (32 =
bits)</U>:
<P></P><I>Binary:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status:</I></FONT> <FONT=20
size=3D-1><INPUT size=3D12 name=3Dstat32></FONT><BR>
<TABLE cellSpacing=3D1 cellPadding=3D5 border=3D1>
  <TBODY>
  <TR align=3Dmiddle>
    <TD><PRE>Bit 31
Sign Bit
<INPUT size=3D1 name=3Dbin32_0>
0: +
1: -
</PRE></TD>
    <TD><PRE>&nbsp;
Bits 30 - 23
Exponent Field
<INPUT size=3D8 name=3Dbin32_1>
Decimal value of exponent field and exponent
<INPUT size=3D3 name=3Dbinpwr32f> - 127 =3D <INPUT size=3D4 =
name=3Dbinpwr32>
</PRE></TD>
    <TD><PRE>&nbsp;
Bits 22 - 0
Significand
<INPUT size=3D26 name=3Dbin32_9>
Decimal value of the significand
<INPUT size=3D9 name=3Ddec32sig>
</PRE></TD></TR></TBODY></TABLE>
<P></P><FONT size=3D4><I>Hexadecimal:</I></FONT> <FONT size=3D-1><INPUT =
size=3D8=20
name=3Dhex32></FONT> <FONT size=3D4>&nbsp;&nbsp;<I>Decimal:</I></FONT> =
<FONT=20
size=3D-1><INPUT size=3D14 name=3Ddec32></FONT>=20
<P></P><BR><BR><FONT size=3D4><U>Double precision (64 bits)</U>:
<P></P><I>Binary:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status:</I></FONT> <FONT=20
size=3D-1><INPUT size=3D12 name=3Dstat64></FONT><BR>
<TABLE cellSpacing=3D1 cellPadding=3D5 border=3D1>
  <TBODY>
  <TR align=3Dmiddle>
    <TD><PRE>Bit 63
Sign Bit
<INPUT size=3D1 name=3Dbin64_0>
0: +
1: -
</PRE></TD>
    <TD><PRE>&nbsp;
Bits 62 - 52
Exponent Field
<INPUT size=3D11 name=3Dbin64_1>
Decimal value of exponent field and exponent
<INPUT size=3D4 name=3Dbinpwr64f> - 1023 =3D <INPUT size=3D5 =
name=3Dbinpwr64></PRE></TD>
    <TD><PRE>&nbsp;
Bits 51 - 0
Significand
<INPUT size=3D55 name=3Dbin64_12>
Decimal value of the significand
<INPUT size=3D18 name=3Ddec64sig>
</PRE></TD></TR></TBODY></TABLE>
<P></P><FONT size=3D4><I>Hexadecimal:</I></FONT> <FONT size=3D-1><INPUT =
size=3D16=20
name=3Dhex64></FONT> <FONT size=3D4>&nbsp;&nbsp;<I>Decimal:</I></FONT> =
<FONT=20
size=3D-1><INPUT size=3D24 name=3Ddec64></FONT> </FONT></FORM><BR>
<HR>
<BR><FONT size=3D-1>
<CENTER>[ <A =
href=3D"http://babbage.cs.qc.edu/IEEE-754/32bit.html">Convert=20
IEEE-754 32-bit Hexadecimal Representations to Decimal Floating-Point=20
Numbers.</A> ]<BR>[ <A=20
href=3D"http://babbage.cs.qc.edu/IEEE-754/64bit.html">Convert IEEE-754 =
64-bit=20
Hexadecimal Representations to Decimal Floating-Point Numbers.</A> =
]<BR>[ <A=20
href=3D"http://babbage.cs.qc.edu/IEEE-754/References.xhtml">Reference =
Material on=20
the IEEE-754 Standard.</A> ]<BR>[ <A =
href=3D"http://babbage.cs.qc.edu/">Dr.=20
Vickery=92s Home Page.</A> ]<BR><BR></CENTER></FONT>
<HR>
<FONT size=3D-2><I>February 1998</I><BR>This page was created by a =
Queens College=20
undergraduate, <A href=3D"mailto:Quanfei.Wen@ca.com">Quanfei Wen</A>, a =
member of=20
<A href=3D"http://www.pbk.org/">PBK</A> and <A=20
href=3D"http://www.qc.edu/~upeqc">UPE</A>. <BR><BR><I>September =
1998</I><BR>The=20
page was revised significantly by <A=20
href=3D"mailto:c2xkjb@eng.delcoelect.com">Kevin J. Brewer</A> of <A=20
href=3D"http://www.delphiauto.com/index.cfm?location=3D312">Delco =
Electronics</A>,=20
who added several features and made significant improvements in how well =
the=20
JavaScript code adheres to the IEEE-754 standard.<BR></FONT>
<HR>
</BASEFONT></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -