double转bit,根据IEEE标准

编写软件vscode+gcc,英文名字乱起的,但每一步都对应着标准来着

#include <iostream>  #include <math.h>  using namespace std; struct DoubleBinary64{  int iExponentLen = 11, iMantissaLen = 52, iDoubleBinLen = iMantissaLen+iExponentLen+1,iExponentsRange=(1<<(iExponentLen-1))-1; }; typedef long long HASH; void GetDoubleBin(char *binArr, double dbNum, DoubleBinary64& dbSt); int GetMantissaBit(char *cArr, double dNum,int iMantissaLen); void GetDecBit(char *ret, int num, int loop); void GetDoubleBin(char *binArr, double dbNum,     DoubleBinary64& dbSt) {      if (dbNum == 0)     {         for (int i = 0; i < dbSt.iDoubleBinLen; i++)         {             binArr[i] = '0';         }         return;     }     int ePath = (int)dbNum, iCount = 0, iMark = 0, iExponentLen = dbSt.iExponentLen     , iMantissaLen = dbSt.iMantissaLen, iDoubleBinLen = dbSt.iDoubleBinLen,iExponentsRange=dbSt.iExponentsRange;     char *fArr, *finArr;     char fExponentArr[iExponentLen+1] = {0}, fMantissa[iMantissaLen+1] = {0}, finMantissa[iMantissaLen+1] = {0};     //循环不能break; 否则无法输出string.函数不能返回指针,否则会被系统回收指针内的内容     if (ePath > 0)     {         while (true)         {             if (ePath < 1)             {                 break;             }             ePath = ePath >> 1;             ++iCount;         }         if (iCount != 0)         {             char fArr2[iCount + 1] = {0};             fArr = fArr2;             ePath = (int)dbNum;             for (int i = 0; i <= iCount; i++)             {                 if (ePath <= 0)                 {                     fArr[i] = '0';                     continue;                 }                 int dnum = 1 << (iCount - i);                 if (dnum > ePath)                 {                     fArr[i] = '0';                 }                 else                 {                     if (iMark == 0)                     {                         iMark = iCount - i;                     }                     fArr[i] = '1';                     ePath = ePath - dnum;                 }             }             iMark = iExponentsRange + iMark;             GetDecBit(fExponentArr, iMark, iExponentLen);             GetMantissaBit(fMantissa, dbNum,iMantissaLen);             iMark = iMark - iExponentsRange;             for (int i = 0; i < iMark; i++)             {                 finMantissa[i] = fArr[iCount - iMark + i + 1];             }             for (int i = 0; i < iMantissaLen; i++)             {                 if (iMark + i >= iMantissaLen)                 {                     break;                 }                 finMantissa[iMark + i] = fMantissa[i];             }         }     }     else     {         iMark = GetMantissaBit(fMantissa, dbNum,iMantissaLen);         iMark = iExponentsRange - iMark;         GetDecBit(fExponentArr, iMark, iExponentLen);         iMark = iExponentsRange - iMark;         for (int i = 0; i < iMantissaLen; i++)         {             if (iMark + i >= iMantissaLen)             {                 finMantissa[i] = '0';             }             else             {                 finMantissa[i] = fMantissa[iMark + i];             }         }     }     if (dbNum > 0)     {         binArr[0] = '0';     }     else     {         binArr[0] = '1';     }     for (int i = 0; i < iExponentLen; i++)     {         binArr[1 + i] = fExponentArr[i];     }     for (int i = 0; i < iMantissaLen; i++)     {         binArr[12 + i] = finMantissa[i];     } } HASH GetDoubleHashByBin(char *binArr,DoubleBinary64& dbSt) {     //正向输出string,反向计算数值     HASH dbHash = 0;     for (int i = dbSt.iDoubleBinLen-1; i != 0; i--)     {         char c = binArr[i];         if (c == '1')         {             dbHash += (1LL << (63 - i));         }     }      return dbHash; } //获取十进制bit,loop表示bit位数,decNum过大时loop位数会溢出 void GetDecBit(char *ret, int decNum, int loop) {     for (int i = 0; i < loop; i++)     {         if (decNum <= 0)         {             ret[i] = '0';             continue;         }         int iSub = 1 << (loop - 1 - i);         if (iSub > decNum)         {             ret[i] = '0';         }         else         {             ret[i] = '1';             decNum = decNum - iSub;         }     } } //获取double在IEEE中规定的尾数bit,返回值为fraction标记 int GetMantissaBit(char *cArr, double dNum,int iMantissaLen) {     double dd = dNum - (int)dNum;     int iMark = 0;     for (int i = 0; i < iMantissaLen; i++)     {         if (dd <= 0)         {             cArr[i] = '0';             continue;         }         double dbpow = pow(2, -(i + 1));         if (dbpow > dd)         {              cArr[i] = '0';         }         else         {             if (iMark == 0)             {                 iMark = i + 1;                 if (iMark >= 52)                 {                     iMark = 51;                 }             }             cArr[i] = '1';             dd = dd - dbpow;         }     }      if (dNum > 1)     {         return 0;     }     return iMark; } int main() {     double dbTest=55.68756;     DoubleBinary64 dbSt;     char dbBinArr[dbSt.iDoubleBinLen+1] = {0};     GetDoubleBin(dbBinArr, dbTest,dbSt);     HASH dbBin2Hash = GetDoubleHashByBin(dbBinArr,dbSt);      cout << dbBin2Hash << endl; } 

  输出:4633034144636536021

  计算机内存中的值:4633034144636536021

  string输出:0100000001001011110110000000000111110111010100010000010011010101

  计算器输出:‭0100000001001011110110000000000111110111010100010000010011010101‬

  如果可以简化代码,请大佬教下,谢谢

推荐这些技术文章:

Maven的标准settings.xml文件

 配置目标
  1. 默认jdk采用java8
  2. 配置阿里云镜像和私服镜像, 并且先从阿里云下载, 下载不到的再去私服下载

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
...

maven 标准setting.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="...

.DAT文件还原数据无法解析,记事本打开情况如下,在线等待。

问题
       &   .   T   .  * N U L L * < 臺 ?l鶺x? 0 , 1 1 8 2 < / 臺 ?l鶺x? < AbChSO巔> 1 1 8 2 , 1 1 1 0 < / AbChSO巔&...

maven配置-编译项目后target中没有对应的xml文件的解决方法

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<inc...

动态代理报错:No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

缺少依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.8</version>
</dependency>
<dependency>
<group...

在build中配置resources,来防止我们资源导出失败的问题

<!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
...

uni-app 布局固定头部,内容滚动

<template>
<view class="container">
<!-- toubu -->
<view class="header">
<text>头部</text>
</view>
<!-- 主要内容 -->
...

委托能在remoting之间传递吗?

问题
<P>public A:MarshalByRefObject</P>
<P>{</P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp; void DoSth(System.Func&lt;string,object,bool&g...

鼠标滑过出现下拉菜单细节处理,高手请进...

问题
如下代码,实现鼠标滑过出现下拉菜单,我有两个问题,请高手帮忙。。。
①如何将下面的内容放在一个table的td中,下拉菜单就显示不出来,除非把table的height值设置够大。但是如果不放在table中该如何排版呢?
②即使不放在table中,如果下面还有内容的话下拉菜单的下半部分会被下面的内容给覆盖掉。这个层次该如何设置?

<ul> <li&...

idea中maven项目target文件不更新

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<includ...

文章标题:double转bit,根据IEEE标准
文章链接:https://www.dianjilingqu.com/390.html
本文章来源于网络,版权归原作者所有,如果本站文章侵犯了您的权益,请联系我们删除,联系邮箱:saisai#email.cn,感谢支持理解。
THE END
< <上一篇
下一篇>>