#include<iostream>
using namespace std;
int main(){
int i;
float f=-6.9072;
//将float指针转换为字符指针
unsigned char* p=reinterpret_cast<unsigned char*>(&f);
cout<<hex;//print bytes of f in hex
for(i=0; i<sizeof(float);i++)
cout<<static_cast<int>(p[i])<<endl;
}C++ reinterpret_cast使用
最新推荐文章于 2024-10-28 11:24:41 发布
本文通过C++代码演示了如何将浮点数转换为字符指针,并以十六进制形式打印其在内存中的字节表示。这对于理解浮点数在计算机内部的存储方式非常有帮助。
382

被折叠的 条评论
为什么被折叠?



