浮点数转换成二进制的方法
2017-04-09 00:50
232 查看
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;
}</span>
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;
}</span>
相关文章推荐
- MODBUS协议 IEEE32位二进制浮点数与十进制小数转换的方法等内容
- MODBUS协议 IEEE32位二进制浮点数与十进制小数转换的方法等内容
- python十进制和二进制的转换方法(含浮点数)
- 十进制转换为二进制 (三种方法实现)
- 十进制转换成二进制、八进制、十六进制的通用方法
- 二进制字节字符转换为ASCII的方法
- 浮点类型强制转换会丢弃小数部分(linux内核中一般不要使用浮点数,解决方法是放大为整数操作)
- 二进制转换为八进制、十进制、十六进制的方法
- 代码分析将double类型的浮点数转换成二进制-实例
- 将以字符串形式给出的浮点数的十六进制形式转换成十进制形式(方法太麻烦,请各位大侠帮忙改进!)
- 十进制转换成二进制、八进制、十六进制的通用方法
- C++中几种将整数转换成二进制输出的方法
- vbs 二进制数据流转换字符串的方法
- 十进制小数转换成二进制小数的快速方法
- 编写程序把一个保存有二进制小数的字符数组转换为浮点数
- float浮点数的二进制存储方式及转换
- 介绍一种将ASCII码字符串转换为二进制字节数据的方法
- 介绍一种将ASCII码字符串转换为二进制字节数据的方法
- 在C#中将二进制数据转换成BASE64字符串的方法
- 十进制浮点小数转换二进制注意的问题点