-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloat.c
96 lines (87 loc) · 2.15 KB
/
float.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
union float_ieee754 {
float dato;
struct {
unsigned int mant:23;
unsigned int exp:8;
unsigned int sign:1;
} ieee754;
struct {
unsigned int b00:1;
unsigned int b01:1;
unsigned int b02:1;
unsigned int b03:1;
unsigned int b04:1;
unsigned int b05:1;
unsigned int b06:1;
unsigned int b07:1;
unsigned int b08:1;
unsigned int b09:1;
unsigned int b10:1;
unsigned int b11:1;
unsigned int b12:1;
unsigned int b13:1;
unsigned int b14:1;
unsigned int b15:1;
unsigned int b16:1;
unsigned int b17:1;
unsigned int b18:1;
unsigned int b19:1;
unsigned int b20:1;
unsigned int b21:1;
unsigned int b22:1;
unsigned int b23:1;
unsigned int b24:1;
unsigned int b25:1;
unsigned int b26:1;
unsigned int b27:1;
unsigned int b28:1;
unsigned int b29:1;
unsigned int b30:1;
unsigned int b31:1;
} bit;
};
void print_bits (float dato) {
union float_ieee754 real = {dato};
printf("%u", real.bit.b31);
printf("%u", real.bit.b30);
printf("%u", real.bit.b29);
printf("%u", real.bit.b28);
printf("%u", real.bit.b27);
printf("%u", real.bit.b26);
printf("%u", real.bit.b25);
printf("%u", real.bit.b24);
printf("%u", real.bit.b23);
printf("%u", real.bit.b22);
printf("%u", real.bit.b21);
printf("%u", real.bit.b20);
printf("%u", real.bit.b19);
printf("%u", real.bit.b18);
printf("%u", real.bit.b17);
printf("%u", real.bit.b16);
printf("%u", real.bit.b15);
printf("%u", real.bit.b14);
printf("%u", real.bit.b13);
printf("%u", real.bit.b12);
printf("%u", real.bit.b11);
printf("%u", real.bit.b10);
printf("%u", real.bit.b09);
printf("%u", real.bit.b08);
printf("%u", real.bit.b07);
printf("%u", real.bit.b06);
printf("%u", real.bit.b05);
printf("%u", real.bit.b04);
printf("%u", real.bit.b03);
printf("%u", real.bit.b02);
printf("%u", real.bit.b01);
printf("%u", real.bit.b00);
printf("\n");
}
int main (void) {
union float_ieee754 real = {3.125};
printf("%u\n", real.ieee754.sign);
printf("%u\n", real.ieee754.exp);
printf("%u\n", real.ieee754.mant);
print_bits(real.dato);
return 0;
}