Archived
1
0
Fork 0
This repository has been archived on 2022-06-20. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_clang/data/showdouble.c

43 lines
1,018 B
C
Raw Normal View History

2022-03-07 15:57:12 +03:00
#include <stdio.h>
union u {
double d;
float f;
unsigned u;
unsigned long long l;
} uu;
int main() {
char s[10] = "";
scanf("%s", s);
if (s[0] == 'f') {
float a;
scanf("%f", &a);
uu.f = a;
int t = 0;
for (int i = sizeof(float) * 8 - 1; i >= 0; i--) {
printf("%d", (uu.u >> i) & 1);
t += 1;
if (t==4) {
t=0;
putchar(' ');
}
}
} else if (s[0] == 'd') {
double a;
scanf("%lf", &a);
uu.d = a;
int t = 0;
for (int i = sizeof(double) * 8 - 1; i >= 0; i--) {
printf("%lld", (uu.l >> i) & 1);
t += 1;
if (t==4) {
t=0;
putchar(' ');
}
}
} else {
printf("0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1011 1111 1111 1111 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000");
}
}