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

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

📁 conversion From 32-bit Hexadecimal Representation To Decimal Floating-Point Along with the Equival
💻 MHT
📖 第 1 页 / 共 3 页
字号:
From: <Saved by Windows Internet Explorer 7>
Subject: IEEE-754 Floating-Point Conversion from 32-bit Hexadecimal to Floating-Point
Date: Mon, 18 May 2009 14:47:23 +0530
MIME-Version: 1.0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://babbage.cs.qc.edu/IEEE-754/32bit.html
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>IEEE-754 Floating-Point Conversion from 32-bit =
Hexadecimal to Floating-Point</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<SCRIPT =3D"javascript">=0A=
/*=0A=
  Copyright (c) 2003, City University of New York=0A=
  All rights reserved.=0A=
=0A=
  Redistribution and use in source and binary forms, with or=0A=
  without modification, are permitted provided that the following=0A=
  conditions are met:=0A=
=0A=
      * Redistributions of source code must retain the above=0A=
      * copyright notice, this list of conditions and the=0A=
      * following disclaimer.  Redistributions in binary form=0A=
      * must reproduce the above copyright notice, this list of=0A=
      * conditions and the following disclaimer in the=0A=
      * documentation and/or other materials provided with the=0A=
      * distribution.  Neither the name of Queens College of CUNY=0A=
      * nor the names of its contributors may be used to endorse=0A=
      * or promote products derived from this software without=0A=
      * specific prior written permission.=0A=
=0A=
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND=0A=
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,=0A=
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF=0A=
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE=0A=
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR=0A=
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A=
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT=0A=
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;=0A=
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)=0A=
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN=0A=
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR=0A=
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,=0A=
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A=
=0A=
  Original version by Quanfei Wen, 1997=0A=
  Modifications by Kevin J. Brewer, 1998/09/20 to 1998/09/30=0A=
=0A=
   - Reordered Hex2Bin and Convert2Bin (with Convert2Bin first) so that =
Unix=0A=
     'diff' has some chance at comparing this file with IEEE-754.html .=0A=
   - General clean-ups.=0A=
   - Found and corrected bug in exponent calculation (and most =
significant bit=0A=
     placement) when converting from a 64-bit normalized value to one =
which=0A=
     must be denormalized in the 32-bit format (normalized to normalized=0A=
     conversion was already fine).=0A=
=0A=
   1998/10/06 to 1998/10/07=0A=
=0A=
   - Added removal of input leading and trailing blanks by adding =
RemoveBlanks=0A=
     routine.=0A=
   - Greatly improved the efficiency of the Convert2Hex routine.=0A=
=0A=
   1998/10/20=0A=
=0A=
   - Allow power of 10 indicator in numStrClipOff to be "E" as well as =
"e" in=0A=
     case not all browsers use "e".=0A=
   - Found and corrected bug in 32-bit binary output created by some =
unknown=0A=
     JavaScript scoping problem for the symbol 'output' by introduction =
of the=0A=
     RemoveBlanks routine.=0A=
=0A=
   1998/10/23=0A=
=0A=
   - All settings of 'this.StatCond' to "normal" were removed in order =
to match=0A=
     IEEE-754.html, "normal" rather than "error" is now the default.=0A=
=0A=
   1998/10/28=0A=
=0A=
   - Redundant code in Convert2Bin "already special values" section to =
that in=0A=
     Hex2Bin removed.=0A=
=0A=
   1999/03/04=0A=
=0A=
   - Corrected displaying error in numStrClipOff when the number of =
digits of=0A=
     precision for a particular IEEE-754 format is less than the number =
of=0A=
     digits returned by the system (before the value is large enough =
that the=0A=
     system returns it in "E" notation).=0A=
     Error found by Bill Maxwell (billmax@compuserve.com).=0A=
=0A=
   1999/03/05=0A=
=0A=
   - The system returns values such as 1.0E21 simply as 1E21.  In =
numStrClipOff,=0A=
     made adjustments to correct the display output when the system =
returns such=0A=
     values.=0A=
     Due to the idealized nature of the input to numStrClipOff vs. that =
of=0A=
     Canonical, many simplifications to the code in numStrClipOff were =
made.=0A=
=0A=
   - Added a Clear button next to the input field which clears the input =
field=0A=
     and all result fields.=0A=
=0A=
   1999/05/17=0A=
=0A=
   - Removed <FONT FACE=3D"Arial"> which is not displayed the same by =
all browser=0A=
     versions.=0A=
=0A=
   - Balanced all <FONT> tags with </FONT> tags.=0A=
=0A=
   - Removed all value layout comments since that information is much =
better=0A=
     presented in the IEEE-754references.html file.=0A=
=0A=
   - Aligned all "Bit xx" and "Bits xx - xx" headings.=0A=
=0A=
   - Replaced all occurrences of the term "unnormalized" with the term=0A=
     "denormalized" preferred by the standard.=0A=
=0A=
   - Changed the "Decimal value of the exponent" display from "b + [e] =
=3D [f]"=0A=
     to "[f] - b =3D [e]" where b =3D 127 or b =3D 1023=0A=
=0A=
   - Headings "Exponent" changed to "Exponent Field" and headings=0A=
     "Decimal value of the exponent" changed to=0A=
     "Decimal value of exponent field and exponent".=0A=
=0A=
   1999/05/28=0A=
=0A=
   - Rounded the 32-bit decimal significand just like the 32-bit full =
decimal=0A=
     value.=0A=
=0A=
   - Fixed displaying problem in numStrClipOff in which values of=0A=
     0.000000099... and smaller (in 32-bit) are displayed as 0.0000000 =
because=0A=
     the values are not small enough for the system to return them in "E"=0A=
     notation and similarly for 0.000000000000000099... and smaller in =
64-bit.=0A=
=0A=
*/=0A=
=0A=
function Convert2Bin(outstring, statstring, signBit, power, rounding)=0A=
{=0A=
  output =3D new String()                 //Output=0A=
=0A=
  var binexpnt, index1, index2, cnst, bias, lastbit, rounded, index3, =
binexpnt2=0A=
  var moreBits=0A=
=0A=
  cnst =3D 2102		// 1 (carry bit) + 1023 + 1 + 1022 + 53 + 2 (round bits)=0A=
  bias =3D 1024=0A=
=0A=
  //init=0A=
  for (index1 =3D 0; index1 < this.Size; index1++)  this.Result[index1] =
=3D 0     =0A=
=0A=
  with (Math) 					=0A=
  {=0A=
    //sign bit=0A=
    this.Result[0] =3D signBit=0A=
=0A=
    //obtain exponent value=0A=
    index1 =3D 0=0A=
=0A=
    if (this.Size =3D=3D 32) index2 =3D 9=0A=
    else index2 =3D 12=0A=
=0A=
    if (rounding && (outstring =3D=3D ""))=0A=
    {=0A=
      //find most significant bit of significand=0A=
      while ((index1 < cnst) && (this.BinVal[index1] !=3D 1)) index1++=0A=
=0A=
      binexpnt =3D bias - index1=0A=
=0A=
      //regular normalized numbers=0A=
      if (binexpnt >=3D this.MinExp)=0A=
      {=0A=
				//the value is shifted until the most=0A=
        index1++		//significant 1 is to the left of the binary=0A=
				//point and that bit is implicit in the encoding=0A=
      }//if normalized numbers=0A=
=0A=
      //support for zero and denormalized numbers=0A=
      //exponent underflow for this precision=0A=
      else=0A=
      {=0A=
        binexpnt =3D this.MinExp - 1=0A=
        index1 =3D bias - binexpnt=0A=
      }//if zero or denormalized (else section)=0A=
=0A=
=0A=
      //use round to nearest value mode=0A=
=0A=
      //compute least significant (low-order) bit of significand=0A=
      lastbit =3D this.Size - 1 - index2 + index1=0A=
=0A=
      //the bits folllowing the low-order bit have a value of (at least) =
1/2=0A=
      if (this.BinVal[lastbit + 1] =3D=3D 1)=0A=
      {=0A=
        rounded =3D 0=0A=
=0A=
        //odd low-order bit=0A=
        if (this.BinVal[lastbit] =3D=3D 1)=0A=
        {=0A=
          //exactly 1/2 the way between odd and even rounds up to the =
even,=0A=
          //so the rest of the bits don't need to be checked to see if =
the value=0A=
          //is more than 1/2 since the round up to the even number will =
occur=0A=
          //anyway due to the 1/2=0A=
          rounded =3D 1=0A=
        }//if odd low-order bit=0A=
=0A=
        //even low-order bit=0A=
        else  //this.BinVal[lastbit] =3D=3D 0=0A=
        {=0A=
          //exactly 1/2 the way between even and odd rounds down to the =
even,=0A=
          //so the rest of the bits need to be checked to see if the =
value=0A=
          //is more than 1/2 in order to round up to the odd number=0A=
          index3 =3D lastbit + 2=0A=
          while ((rounded =3D=3D 0) && (index3 < cnst))=0A=
          {=0A=
            rounded =3D this.BinVal[index3]=0A=
            index3++=0A=
          }//while checking for more than 1/2=0A=
=0A=
        }//if even low-order bit (else section)=0A=
=0A=
        //do rounding "additions"=0A=
        index3 =3D lastbit=0A=
        while ((rounded =3D=3D 1) && (index3 >=3D 0))=0A=
        {=0A=
          // 0 + 1 -> 1 result with 0 carry=0A=
          if (this.BinVal[index3] =3D=3D 0)=0A=
          {=0A=
            // 1 result=0A=
            this.BinVal[index3] =3D 1=0A=
=0A=
            // 0 carry=0A=
            rounded =3D 0=0A=
=0A=
          }//if bit is a 0=0A=
=0A=
          // 1 + 1 -> 0 result with 1 carry=0A=
          else  //this.BinVal[index3] =3D=3D 1=0A=
          {=0A=
            // 0 result=0A=
            this.BinVal[index3] =3D 0=0A=
=0A=
            // 1 carry=0A=
//          rounded =3D 1=0A=
          }//if bit is a 1 (else section)=0A=
=0A=
          index3--=0A=
        }//while "adding" carries from right to left in bits=0A=
=0A=
      }//if at least 1/2=0A=
=0A=
      //obtain exponent value=0A=
      index1 =3D index1 - 2=0A=
      if (index1 < 0) index1 =3D 0=0A=
=0A=
    }//if rounding=0A=
=0A=
    //find most significant bit of significand=0A=
    while ((index1 < cnst) && (this.BinVal[index1] !=3D 1)) index1++=0A=
=0A=
    binexpnt2 =3D bias - index1=0A=
=0A=
    if (outstring =3D=3D "")=0A=
    {=0A=
      binexpnt =3D binexpnt2=0A=
=0A=
      //regular normalized numbers=0A=
      if ((binexpnt >=3D this.MinExp) && (binexpnt <=3D this.MaxExp))=0A=
      {=0A=
                                //the value is shifted until the most=0A=
        index1++                //significant 1 is to the left of the =
binary=0A=
                                //point and that bit is implicit in the =
encoding=0A=
      }//if normalized numbers=0A=
=0A=
      //support for zero and denormalized numbers=0A=
      //exponent underflow for this precision=0A=
      else if (binexpnt < this.MinExp)=0A=
      {=0A=
        if (binexpnt2 =3D=3D bias - cnst)=0A=
          //value is truely zero=0A=
          this.StatCond =3D "normal"=0A=
        else if (binexpnt2 < this.MinUnnormExp)=0A=
          this.StatCond =3D "underflow"=0A=
        else=0A=
          this.StatCond =3D "denormalized"=0A=
=0A=
        binexpnt =3D this.MinExp - 1=0A=
        index1 =3D bias - binexpnt=0A=
      }//if zero or denormalized (else if section)=0A=
    }=0A=
=0A=
    else //already special values=0A=
    {=0A=
      binexpnt =3D power=0A=
      index1 =3D bias - binexpnt=0A=
=0A=
      //compute least significant (low-order) bit of significand=0A=
      lastbit =3D this.Size - 1 - index2 + index1=0A=
=0A=
      moreBits =3D this.BinVal[lastbit]=0A=
=0A=
      index3 =3D lastbit + 1=0A=
      while ((moreBits =3D=3D 0) && (index3 < cnst))=0A=
      {=0A=
        moreBits =3D this.BinVal[index3]=0A=
        index3++=0A=
      }//while checking for more bits from other precision=0A=
=0A=
      this.BinVal[lastbit] =3D moreBits=0A=
=0A=
    }//if already special (else section)=0A=
=0A=
    //copy the result=0A=
    while ((index2 < this.Size) && (index1 < cnst))=0A=
    {=0A=
      this.Result[index2] =3D this.BinVal[index1]=0A=
      index2++=0A=
      index1++=0A=
    }//while=0A=
=0A=
    //max exponent for this precision=0A=
    if ((binexpnt > this.MaxExp) || (outstring !=3D ""))=0A=
    {=0A=
      binexpnt =3D this.MaxExp + 1=0A=
=0A=
      //overflow of this precision, set infinity=0A=

⌨️ 快捷键说明

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