警告:左移计数 >= 在 C++ 中将字节流读取为双精度变量时的类型宽度
Warning: left shift count >= width of type when reading bytestream into double variable in C++
我正在尝试将字节流读入C++中的双变量。 所以我的代码如下:
double foo;
foo = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24) | (bytes[44] << 32) | (bytes[5] << 40) | (bytes[6] << 48) | (bytes[7] << 56);
如您所见,我正在尝试以 64 位读取。尽管 double 不是固定大小,但在几乎任何机器上都应该是 64 位。(sizeof(double)
给我 8 个字节作为大小(
但我仍然收到此警告:
警告:左移计数>= 字体宽度
我可以忽略该警告 - 或者我可以以某种方式使双精度固定的大小固定(因为我知道 C/C++ 中没有 sizefixed 浮点数据类型(?
感谢您的帮助!
我为自己找到了解决方案-但感谢所有评论!
我试了memcpy()
,效果很好。
我是这样解决的:
foo = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24) | ((uint64_t)bytes[44] << 32) | ((uint64_t)bytes[5] << 40) | ((uint64_t)bytes[6] << 48) | ((uint64_t)bytes[7] << 56);
相关文章:
- 正在将csv文件读取为双精度矢量
- 为什么 Clang std::ostream 写一个 std::istream 无法读取的双精度?
- 从二进制流中读取时,将双精度变量的地址转换为 char* 意味着什么?
- 如何从char16_t字符串文字中读取双精度?
- 从.txt文件读取到C++中的双精度向量
- 警告:左移计数 >= 在 C++ 中将字节流读取为双精度变量时的类型宽度
- 我想读取文本文件中的所有内容(但文本文件中只有一个双精度值),转换为双精度值并返回值
- 为什么当我使用双精度时,Qt<->Matlab 正确写入和读取我的字节,但存储 uint32 的字节不正确?
- 为什么 i(f)流无法读取双精度
- 从二进制文件中保存的 4 字节双精度读取 8 字节双精度
- 如何从二进制文件中读取双精度并将其保存在向量中
- 有没有办法更有效地将二进制双精度从文件读取到浮点数组中
- 如何在OpenCV中将图像读取为双精度
- 使用 sscanf 读取双精度时忽略"E"
- C++ - 从文件读取到双精度
- C++ 从文本文件中读取,双精度行
- 从C++中的文本文件中逐行读取,如何确保输入是双精度的
- 从文件中读取长双精度,然后写入另一个文件
- 从十六进制数组读取双精度到向量
- 什么更贵?读取或比较整数,双精度