QT c++ 双精度数拆分和组合 Tool

本文描述QT c++的双精度数拆分和合并,即双精度浮点数拆为四个16位无符号整数以及将四个16位无符号整数组合为双精度浮点数。

开发平台:win10+QT6.2.4 MSVC2019 64 bit

在本文的最好列出了代码和可执行文件打包下载链接(可直接使用)。

1.界面如下

2.头文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
union DoubleSplit
{
    double doubleValue; // 64位,双精度数
    struct {
        unsigned short  Word0;
        unsigned short  Word1;
        unsigned short  Word2;
        unsigned short  Word3;
    } sDoubleValues;       // 结构体,包含4个16位无符号整数
    unsigned short ShortArray[4];
};

QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_bt_DoubleTo4Words_clicked();

    void on_bt_4WordsToDouble_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

3.cpp文件

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_bt_DoubleTo4Words_clicked()//将双精度浮点数拆为四个16位无符号整数
{
    DoubleSplit ds;
    ds.doubleValue=ui->doubleSpinBox->value();
    ui->spinBox0->setValue((unsigned short)ds.ShortArray[0]);
    ui->spinBox1->setValue((unsigned short)ds.ShortArray[1]);
    ui->spinBox2->setValue((unsigned short)ds.ShortArray[2]);
    ui->spinBox3->setValue((unsigned short)ds.ShortArray[3]);
   ;
}


void Widget::on_bt_4WordsToDouble_clicked()//将四个16位无符号整数合并为双精度浮点数
{
    DoubleSplit ds;
    ds.ShortArray[0]=(unsigned short)ui->spinBox0->value();
    ds.ShortArray[1]=(unsigned short)ui->spinBox1->value();
    ds.ShortArray[2]=(unsigned short)ui->spinBox2->value();
    ds.ShortArray[3]=(unsigned short)ui->spinBox3->value();
    ui->doubleSpinBox->setValue((double)ds.doubleValue);
}

4.代码下载链接如下:

https://download.csdn.net/download/weixin_39926429/88962945

5.可执行文件下载链接如下:

https://download.csdn.net/download/weixin_39926429/88963277

相关推荐

  1. P2404 自然问题

    2024-03-18 06:46:04       15 阅读
  2. P2404 自然问题 题解

    2024-03-18 06:46:04       11 阅读
  3. C 语言实例 - 输出精度(double)

    2024-03-18 06:46:04       10 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-18 06:46:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-18 06:46:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-18 06:46:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-18 06:46:04       18 阅读

热门阅读

  1. 大语言模型相关工具使用链接

    2024-03-18 06:46:04       20 阅读
  2. LLaMA-2 简介:开源大型语言模型的新篇章

    2024-03-18 06:46:04       19 阅读
  3. Linux初级知识大全(一)

    2024-03-18 06:46:04       20 阅读
  4. Spark 用AnyFunSuite单元测试Scala详细教程

    2024-03-18 06:46:04       17 阅读
  5. 如何杀死服务器出现的僵尸进程

    2024-03-18 06:46:04       23 阅读
  6. ChatGPT:论文写作的新潮解决方案

    2024-03-18 06:46:04       20 阅读
  7. Linux TCP参数——tcp_abort_on_overflow

    2024-03-18 06:46:04       21 阅读
  8. 系统开发中的快速测试与调试策略

    2024-03-18 06:46:04       22 阅读