/* * simple hacked-up program to show (in hexadecimal) the bit representation * of a floating-point number. * * bytes are printed in memory order, which for little-endian architectures * is least-significant first. */ #include #include #include "show-bytes.c" int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "usage %s number\n", argv[0]); return EXIT_FAILURE; } char * endptr; double d = strtod(argv[1], &endptr); if (*endptr != '\0') { fprintf(stderr, "not numeric\n"); return EXIT_FAILURE; } float f = d; fprintf(stdout, "input value %g\n", d); fprintf(stdout, "as double: "); show_bytes(stdout, &d, sizeof d); fprintf(stdout, "\n"); fprintf(stdout, "as float: "); show_bytes(stdout, &f, sizeof f); fprintf(stdout, "\n"); return EXIT_SUCCESS; }