/*
 * simple hacked-up program to show (in hexadecimal) the bit representation
 * of an integer.
 *
 * bytes are printed in memory order, which for little-endian architectures
 * is least-significant first.
 */
#include <stdio.h>
#include <stdlib.h>

#include "show-bytes.c"

int main(int argc, char *argv[]) {
    if (argc < 2) {
        fprintf(stderr, "usage %s integer\n", argv[0]);
        return EXIT_FAILURE;
    }
    char * endptr;
    long n = strtol(argv[1], &endptr, 10);
    if (*endptr != '\0') {
        fprintf(stderr, "not integer\n");
        return EXIT_FAILURE;
    }
    fprintf(stdout, "input value %ld\n", n);
    fprintf(stdout, "as long:  ");
    show_bytes(stdout, &n, sizeof n);
    fprintf(stdout, "\n");
    fprintf(stdout, "as short:  ");
    show_bytes(stdout, &n, sizeof (short));
    fprintf(stdout, "\n");
    return EXIT_SUCCESS;
}