您的位置:首页 > 其它

关于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题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: