浮点数转换成二进制的方法
- 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>
posted on 2017-04-09 00:50 shoutcharter 阅读(1870) 评论(0) 编辑 收藏 举报