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

30 篇文章 0 订阅
本文详细介绍了如何在Win10环境下,利用QT6.2.4和MSVC2019编译器实现双精度浮点数到四个16位无符号整数的拆分,以及反之的合并过程,提供了相应的代码和可执行文件下载链接。
摘要由CSDN通过智能技术生成

本文描述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

  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值