#include <stdio.h> int main() { float num; scanf("%f", &num); int Z[258] = {0}, X[258] = {0}, PRINT[32] = {0}, P[258] = {0}; int m, n, p, e = 0, E = 0; int mid = 0; if (num < 0) { PRINT[0] = 1; num = -num; } if (num > 1) { E = 1; } while (num > 1) { mid++; num--; } for (m = -1; mid > 0;) { m++; if (mid % 2 == 1) { Z[m] = 1; } mid = mid / 2; } if (E == 1) { e = m; } for (n = 0; m >= 0; m--, n++) { P[n] = Z[m]; } for (m = 0; num != 0 && m < 258; m++) { num = num * 2; if (num >= 1) { X[m] = 1; num--; } } if (E != 1) { e = -1; while (X[e] = 0) { e--; } } for (p = 0; n <= 257 && p < m; p++, n++) { P[n] = X[p]; } for (e = e + 127, m = 8; m >= 1; m--) { if (e % 2 == 1) { PRINT[m] = 1; } e = e / 2; } int c = 0; while (P[c] == 0) { c++ ; } c++; c = n - c; for (m = 9; m <= 31; m++, c++) { PRINT[m] = P[c]; } for (m = 0; m <= 31; m++) { printf("%d", PRINT[m]); } return 0; }
标签:int,++,浮点数,mid,--,258,num From: https://www.cnblogs.com/hehuanwu4714/p/16735886.html