// 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;
//
#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题