-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfclassify.cpp
More file actions
41 lines (35 loc) · 798 Bytes
/
Copy pathfclassify.cpp
File metadata and controls
41 lines (35 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
bitset<32> getbits(float f) {
union {
float input;
unsigned int output;
} data;
data.input = f;
bitset<32> bits(data.output);
return bits;
}
enum class FPClass
{
ZERO, DENORMALIZED, NORMALIZED, INF, NAN
};
int main() {
float f;
while (cin >> f) {
bits = getbits(f);
unsigned int exponent = 0;
for (int i = 0; i < 8; ++i) {
exponent += bits[23 + i] * (1 << i);
}
unsigned int frac = 0;
for (int i = 0; i < 23; ++i) {
frac += bits[i] * (1 << i);
}
cout << dec << bits[31] << " " << exponent << " ";
cout << hex << frac << endl;
}
}