关于float的移位问题++
2017-09-22 21:21
190 查看
// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<bitset>
#include<iomanip>
using namespace std;
int main() {
float f;
cin >> f;
int *p;
p = (int *)(&f);
//cout << bitset<sizeof(int) * 8>(*p)<<endl;
float *r;
int x = ((~(*p >> 31))& 0x00000001) << 31;
//cout << bitset<sizeof(int) * 8>(x) << endl;
int t = *p | x;
//r = (float *)(&x);
//cout << bitset<sizeof(int) * 8>(*r) << endl;
r=(float *)(&t);
cout << *r << endl;
}
源于《深入理解计算机系统》2.92题
//
#include "stdafx.h"
#include<iostream>
#include<bitset>
#include<iomanip>
using namespace std;
int main() {
float f;
cin >> f;
int *p;
p = (int *)(&f);
//cout << bitset<sizeof(int) * 8>(*p)<<endl;
float *r;
int x = ((~(*p >> 31))& 0x00000001) << 31;
//cout << bitset<sizeof(int) * 8>(x) << endl;
int t = *p | x;
//r = (float *)(&x);
//cout << bitset<sizeof(int) * 8>(*r) << endl;
r=(float *)(&t);
cout << *r << endl;
}
源于《深入理解计算机系统》2.92题
相关文章推荐
- 关于EditorGridPanel移位的问题
- 关于CSS中内层使用float导致外层的背景无法显示的问题的解决
- 关于int数据转换float数据出现输出0.0000的问题
- 关于char字符移位问题
- 关于ie6、ie7折行问题(li用了float)
- 关于float的自动换行问题
- 实习小结七:html布局问题--关于float和clear
- 关于char字符移位问题
- 关于float double的数据类型的细节,在处理转换问题的时候非常有用
- 关于布局中float的常见问题及解决办法
- 关于取反、移位、类型转换需要注意的一些问题
- 关于PHP官网的float转int精度问题
- 关于Double、Float精度修改问题
- 关于C语言的文件型指针和移位操作中的一些有趣问题的探讨
- 关于CSS中内层使用float导致外层的背景无法显示的问题的解决方法
- 关于C中float和double的一些问题
- 关于自加++,左值的问题
- 关于css中float出现元素高度为0的问题的若干意见
- java 关于-2>>3之类的移位问题
- 关于double/float运算精度问题