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

📄 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 页
字号:
      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) || (statstring !=3D "normal"))=0A=
    {=0A=
      //overflow of this precision, set infinity=0A=
      if (statstring =3D=3D "normal")=0A=
      {=0A=
        binexpnt =3D this.MaxExp + 1=0A=
        this.StatCond =3D "overflow"=0A=
        this.DispStr =3D "Infinity"=0A=
=0A=
        if (this.Result[0] =3D=3D 1)=0A=
          this.DispStr =3D "-" + this.DispStr=0A=
=0A=
        if (this.Size =3D=3D 32) index2 =3D 9=0A=
        else index2 =3D 12=0A=
=0A=
        //zero the significand=0A=
        while (index2 < this.Size)=0A=
        {=0A=
          this.Result[index2] =3D 0=0A=
          index2++=0A=
        }//while=0A=
=0A=
      }//if overflowed=0A=
=0A=
      else //already special values=0A=
      {=0A=
        this.StatCond =3D statstring=0A=
        this.DispStr =3D outstring=0A=
      }//if already special (else section)=0A=
=0A=
    }//if max exponent=0A=
=0A=
    //convert exponent value to binary representation=0A=
    if (this.Size =3D=3D 32) index1 =3D 8=0A=
    else index1 =3D 11=0A=
    this.BinaryPower =3D binexpnt=0A=
    binexpnt +=3D this.ExpBias    //bias=0A=
    while ((binexpnt / 2) !=3D 0)=0A=
    {=0A=
      this.Result[index1] =3D binexpnt % 2=0A=
      if (binexpnt % 2 =3D=3D 0) binexpnt =3D binexpnt / 2=0A=
        else binexpnt =3D binexpnt / 2 - 0.5=0A=
      index1 -=3D 1=0A=
    }=0A=
=0A=
    //output binary result=0A=
    output =3D ""=0A=
    for (index1 =3D 0; index1 < this.Size; index1++)=0A=
      output =3D output + this.Result[index1]=0A=
    return output=0A=
=0A=
  }//with Math=0A=
}=0A=
=0A=
function Dec2Bin(input)=0A=
{=0A=
  var value, intpart, decpart, binexpnt, index1, cnst, bias=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 < cnst; index1++)  this.BinVal[index1] =3D 0=0A=
=0A=
  with (Math)=0A=
  {=0A=
    input =3D Canonical(input)=0A=
=0A=
    //sign bit=0A=
    if (input.charAt(0) =3D=3D "-")=0A=
      this.Result[0] =3D 1=0A=
    else=0A=
      this.Result[0] =3D 0=0A=
=0A=
    //if value magnitude greater than 1.7976931348623157E+308, set =
infinity=0A=
    input =3D OvfCheck(input)=0A=
=0A=
    if (input.indexOf("Infinity") !=3D -1)=0A=
    {=0A=
      binexpnt =3D this.MaxExp + 1=0A=
      this.StatCond64 =3D "overflow"=0A=
      this.DispStr =3D input=0A=
=0A=
    }//if greater than 1.7976931348623157E+308=0A=
=0A=
    //Value magnitude is not greater than 1.7976931348623157E+308=0A=
    else=0A=
    {=0A=
=0A=
      //if value magnitude less than 2.4703282292062328E-324, set =
"underflow".=0A=
      this.StatCond64 =3D UndfCheck(input)=0A=
=0A=
      if (this.StatCond64 =3D=3D "underflow")=0A=
      {=0A=
        binexpnt =3D this.MinExp - 1=0A=
=0A=
      }//if less than 2.4703282292062328E-324=0A=
=0A=
      //Value magnitude is not less than 2.4703282292062328E-324=0A=
      else=0A=
      {=0A=
=0A=
        //convert 'input' from string to numeric=0A=
        input =3D input * 1.0=0A=
=0A=
        //convert and seperate input to integer and decimal parts=0A=
        value =3D abs(input)=0A=
        intpart =3D floor(value)=0A=
        decpart =3D value - intpart=0A=
=0A=
        //convert integer part=0A=
        index1 =3D bias=0A=
        while (((intpart / 2) !=3D 0) && (index1 >=3D 0))=0A=
        {=0A=
          this.BinVal[index1] =3D intpart % 2=0A=
          if (intpart % 2 =3D=3D 0) intpart =3D intpart / 2=0A=
            else intpart =3D intpart / 2 - 0.5=0A=
          index1 -=3D 1=0A=
        }=0A=
=0A=
        //convert decimal part=0A=
        index1 =3D bias + 1=0A=
        while ((decpart > 0) && (index1 < cnst))=0A=
        {=0A=
          decpart *=3D 2=0A=
          if (decpart >=3D 1)=0A=
            {this.BinVal[index1] =3D 1; decpart --; index1++}=0A=
          else {this.BinVal[index1] =3D 0; index1++}=0A=
        }=0A=
=0A=
        //obtain exponent value=0A=
        index1 =3D 0=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=
        //support for zero and denormalized numbers=0A=
        //exponent underflow for this precision=0A=
        if (binexpnt < this.MinExp)=0A=
        {=0A=
          binexpnt =3D this.MinExp - 1=0A=
=0A=
        }//if zero or denormalized=0A=
=0A=
      }//if not less than 2.4703282292062328E-324 (else section)=0A=
=0A=
    }//if not greater than 1.7976931348623157E+308 (else section)=0A=
=0A=
    //output exponent value=0A=
    this.BinaryPower =3D binexpnt=0A=
=0A=
  }//with Math=0A=
}=0A=
=0A=
function Canonical(input)=0A=
{=0A=
  output =3D new String()=0A=
  numerals =3D new String()=0A=
  expstr =3D new String()=0A=
  signstr =3D new String()=0A=
  expsignstr =3D new String()=0A=
  expstrtmp =3D new String()=0A=
=0A=
  var locE, stop, expnum, locDPact, locDP, start, MSDfound, index, =
expdelta=0A=
  var expstart, expprecision=0A=
=0A=
  numerals =3D "0123456789";=0A=
=0A=
  expprecision =3D 5=0A=
=0A=
  input =3D input.toUpperCase()=0A=
=0A=
  locE =3D input.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=
  locDPact =3D input.indexOf(".");=0A=
  if (locDPact !=3D -1)=0A=
    locDP =3D locDPact=0A=
  else=0A=
    locDP =3D stop=0A=
=0A=
  start =3D 0=0A=
  if (input.charAt(start) =3D=3D "-")=0A=
  {=0A=
    start++=0A=
    signstr =3D "-"=0A=
  }=0A=
  else if (input.charAt(start) =3D=3D "+")=0A=
  {=0A=
    start++=0A=
    signstr =3D "+"=0A=
  }=0A=
  else=0A=
    signstr =3D "+"=0A=
=0A=
  MSDfound =3D false=0A=
  while ((start < stop) && !MSDfound)=0A=
  {=0A=
    index =3D 1=0A=
    while (index < numerals.length)=0A=
    {=0A=
      if (input.charAt(start) =3D=3D numerals.charAt(index))=0A=
      {=0A=
        MSDfound =3D true=0A=
        break=0A=
      }=0A=
      index++=0A=
    }=0A=
    start++=0A=
  }=0A=
  start--=0A=
=0A=
  if (MSDfound)=0A=
  {=0A=
    expdelta =3D locDP - start=0A=
    if (expdelta > 0)=0A=
      expdelta =3D expdelta - 1=0A=
=0A=
    expnum =3D expnum + expdelta=0A=
  }=0A=
  else  //No significant digits found, value is zero=0A=
    expnum =3D 0=0A=
=0A=
  expstrtmp =3D "" + expnum=0A=
=0A=
  expstart =3D 0=0A=
  if (expstrtmp.charAt(expstart) =3D=3D "-")=0A=
  {=0A=
    expstart++=0A=
    expsignstr =3D "-"=0A=
  }=0A=
  else=0A=
    expsignstr =3D "+"=0A=
=0A=
  expstr =3D "E" + expsignstr=0A=
=0A=
  index =3D 0=0A=
  while (index < expprecision - expstrtmp.length + expstart)=0A=
  {=0A=
    expstr +=3D "0"=0A=
    index++=0A=
  }=0A=
=0A=
  expstr +=3D expstrtmp.substring(expstart, expstrtmp.length)=0A=
=0A=
  output =3D signstr=0A=
=0A=
  if (locDPact =3D=3D start + 1)=0A=
  {=0A=
    output +=3D input.substring(start, stop)=0A=
  }=0A=
  else if (stop =3D=3D start + 1)=0A=
  {=0A=
    output +=3D input.substring(start, stop)=0A=
    output +=3D "."=0A=
  }=0A=
  else if (locDPact < start)=0A=
  {=0A=
    output +=3D input.substring(start, start + 1)=0A=
    output +=3D "."=0A=
    output +=3D input.substring(start + 1, stop)=0A=
  }=0A=
  else if (locDPact !=3D -1)=0A=
  {=0A=
    output +=3D input.substring(start, start + 1)=0A=
    output +=3D "."=0A=
    output +=3D input.substring(start + 1, locDPact)=0A=
    output +=3D input.substring(locDPact + 1, stop)=0A=
  }=0A=
  else=0A=
  {=0A=
    output +=3D input.substring(start, stop)=0A=
    output +=3D "."=0A=
  }=0A=
=0A=
  output +=3D expstr=0A=
=0A=
  return output;=0A=
}=0A=
=0A=
function MostSigOrder(input)=0A=
{=0A=
  output =3D new String()=0A=
  expstr =3D new String()=0A=
=0A=
  var expprecision, expbias, stop, expnum, index=0A=
=0A=
  expprecision =3D 5=0A=
  expbias =3D 50000=0A=
=0A=
  stop =3D input.indexOf("E");=0A=
=0A=
  output =3D input.substring(stop + 1, input.length)=0A=
  expnum =3D output * 1=0A=
  expnum +=3D expbias=0A=
=0A=
  expstr =3D "" + expnum=0A=
=0A=
  output =3D expstr=0A=
=0A=
  index =3D 0=0A=
  while (index < expprecision - expstr.length)=0A=
  {=0A=
    output =3D "0" + output=0A=
    index++=0A=
  }=0A=
=0A=
  output +=3D input.substring(1, 2)=0A=
  output +=3D input.substring(3, stop)=0A=
=0A=
  return output;=0A=
}=0A=
=0A=
function A_gt_B(A, B)=0A=
{=0A=
  numerals =3D new String()=0A=
=0A=
  var greater, stop, index, Adigit, Bdigit=0A=
=0A=
  numerals =3D "0123456789";=0A=
=0A=
  greater =3D false=0A=
=0A=
  if (A.length > B.length)=0A=
    stop =3D A.length=0A=
  else=0A=
    stop =3D B.length=0A=
=0A=
  index =3D 0=0A=
  while (index < stop)=0A=
  {=0A=
    if (index < A.length)=0A=
      Adigit =3D numerals.indexOf(A.charAt(index))=0A=
    else=0A=
      Adigit =3D 0=0A=
=0A=
    if (index < B.length)=0A=
      Bdigit =3D numerals.indexOf(B.charAt(index))=0A=
    else=0A=
      Bdigit =3D 0=0A=
=0A=
    if (Adigit < Bdigit)=0A=
      break=0A=
    else if (Adigit > Bdigit)=0A=
    {=0A=
      greater =3D true=0A=
      break=0A=
    }=0A=
=0A=
    index++=0A=
  }//end while=0A=
=0A=
  return greater;=0A=
}=0A=
=0A=
function OvfCheck(input)=0A=
{=0A=
  output =3D new String()=0A=
=0A=
  //Is value magnitude greater than +1.7976931348623157E+00308=0A=
  if (A_gt_B(MostSigOrder(input), "5030817976931348623157"))=0A=
  {=0A=
    output =3D "Infinity"=0A=
    if (input.charAt(0) =3D=3D "-")=0A=
      output =3D "-" + output=0A=
  }=0A=
  else=0A=
    output =3D input=0A=
=0A=
  return output;=0A=
}=0A=
=0A=
function UndfCheck(input)=0A=
{=0A=
  output =3D new String()=0A=
=0A=
  //Is value magnitude less than +2.4703282292062328E-00324=0A=
  if (A_gt_B("4967624703282292062328", MostSigOrder(input)))=0A=
    output =3D "underflow"=0A=
  else=0A=
    output =3D "normal"=0A=
=0A=
  return output;=0A=
}=0A=
=0A=
function RemoveBlanks(input)=0A=
{=0A=
  output =3D new String()=0A=
=0A=
  var start, stop=0A=
=0A=
  start =3D 0=0A=
  while ((input.charAt(start) =3D=3D " ") && (start < input.length))=0A=
    start++=0A=
=0A=
  stop =3D input.length - 1=0A=
  while ((input.charAt(stop) =3D=3D " ") && (stop >=3D 0))=0A=
    stop--=0A=
=0A=
  output =3D input.substring(start, stop + 1)=0A=
=0A=
  return output=0A=
}=0A=
=0A=
function Convert2Hex()=0A=
{=0A=
  output =3D new String()=0A=
  numerals =3D new String()=0A=
=0A=
  var temp, index, i=0A=
=0A=
  numerals =3D "0123456789ABCDEF"=0A=
=0A=
  with (Math)=0A=
  {=0A=
    //convert binary result to hex and output=0A=
    for (index =3D 0; index < this.Size; index +=3D4)=0A=
    {=0A=
      temp =3D 0=0A=
      for (i =3D 0; i < 4; i++)=0A=
        temp +=3D pow(2, 3 - i)*this.Result[index + i]=0A=
=0A=
      output =3D output + numerals.charAt(temp)=0A=
    }=0A=
  }=0A=
  return output=0A=
}=0A=
=0A=
function numStrClipOff(input, precision)=0A=
{=0A=
  result =3D new String()=0A=

⌨️ 快捷键说明

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