首页 > 其他分享 >Qbytearray 与 float , int 等互转

Qbytearray 与 float , int 等互转

时间:2023-01-20 21:33:06浏览次数:34  
标签:cast int float reinterpret 互转 sizeof buff

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QByteArray buff;
    float ff = 1.234f, f2;
    int ii = 345,i2;


//    int len = sizeof(int) + sizeof(float);
//    buff.resize(8);
//    qDebug()<< "size=" << buff.size();
    buff.append(reinterpret_cast<const char*>(&ii),sizeof(ii));
    buff.append(reinterpret_cast<const char*>(&ff),sizeof(ff));
//    i2 = *reinterpret_cast<const int*>(buff.data());
//    f2 = *reinterpret_cast<const float*>(buff.data()+sizeof(int));
//    qDebug() << len << " " <<  buff.size() << " " <<  ii << " " << i2 << " " << ff <<" " << f2;
    i2 = *reinterpret_cast<const int*>(buff.data());
    f2 = *reinterpret_cast<const float*>(buff.data()+sizeof(ii));
    qDebug() <<  buff.size() << " " <<  ii << " " << i2 << " " << ff <<" " << f2;

    return a.exec();
}

标签:cast,int,float,reinterpret,互转,sizeof,buff
From: https://www.cnblogs.com/xihong2014/p/17063269.html

相关文章

  • SMU Winter 2023 Round #6 (Div.2)
    A.OP题目:现在请你喊出某次神秘活动中的口号"fengqibisheng,yingyueerlai!"(不包含引号)。思路:这道题输出这句话就行B.Add9Zeros题目:题意就是将数组A中的数加9后拿......
  • SMU Winter 2023 Round #7 (Div.2)
    A.解开束缚缠丝II题意:在一堆字符里面找出最长的回文串,并把它的长度输出出来。思路:这道题,一开始想的是把所有情况都列举出来,然后一一判断是不是回文串。后面根据第二个......
  • scanf 与 printf
    sacnf与printf在头文件cstdio中,sacnf与printf在数据规模较大时效率高于cin与cout需要注意的是scanf变量需要取地址1.格式化输出-保留小数位printf输出小数时默认保留6位......
  • 2023WinterHoliday刷题总结第一弹
    \(2023WinterHoliday\)刷题总结第一弹\(CTF\)\(Web\)1.\(json格式:\)$json['x']=="wllm"\(JSON\)(JavaScriptObjectNotation,JS对象简谱)是一种轻量级的数据交换格式,采......
  • 23/1/119-LeetCode 08:String to Integer (atoi)
    思路主要是对于前面的零,可以不用再去特殊判断了嘛。直接当成普通的数字直接算就好,反正算完之后ans=0,nodifference;对于超出范围,这个一直都是我不太注意的地方,这里max=2^......
  • go打印fmt.Println指针的逃逸问题的注意,打印的顺序
    问题1:funcmain(){model.DBNew("./conf.toml")varuser[]model.CoreGrainedmodel.DB().Find(&user)for_,i:=rangeuser{vargg[]stringe......
  • Spring AOP中@Pointcut切入点表达式详解
    目录一、瞅一眼标准的AspectJAop的pointcut的表达式二、SpringAop的十一种AOP表达式三、演示使用1、execution:2、within:3、this:4、target:5、args:6、@target:7、......
  • 第五十章 使用 ^SystemPerformance 监视性能 - Microsoft Windows 平台的 InterSystem
    第五十章使用^SystemPerformance监视性能-MicrosoftWindows平台的InterSystemsIRIS性能数据报告MicrosoftWindows平台的IRIS性能数据报告%SS-使用ALL......
  • 智能文本自动处理(Intelligent text automatic processing)
    AutoText智能文本自动处理工具(Intelligenttextautomaticprocessingtool)。项目地址:https://github.com/jiangnanboy/AutoTextAutoText的功能主要有文本纠错,图片ocr以......
  • 浅谈BeanDefinition、BeanDefinitionMap、RootBeanDefintion三者的关系
    文章目录​​一、BeanDefinition​​​​1、具体实现子类​​​​2、手动创建子类​​​​3、beanClass成员变量的含义​​​​二、BeanDefinitionMap​​​​三、RootBeanD......