Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
/* Example code for Think OS.
2
3
Copyright 2014 Allen Downey
4
License: GNU GPLv3
5
6
*/
7
8
#include <stdio.h>
9
#include <stdlib.h>
10
11
12
int main ()
13
{
14
union {
15
float f;
16
unsigned int u;
17
} p;
18
19
p.f = -13.0;
20
unsigned int sign = (p.u >> 31) & 1;
21
unsigned int exp = (p.u >> 23) & 0xff;
22
23
unsigned int coef_mask = (1 << 23) - 1;
24
unsigned int coef = p.u & coef_mask;
25
26
printf("%d\n", sign);
27
printf("%d\n", exp);
28
printf("0x%x\n", coef);
29
30
return 0;
31
}
32
33