3089
2018-10-09 17:22:03
0
#include <stdio.h>
#include <stdint.h>
#ifndef __GNUC__
#error Only GNUC is supported
#endif
#if __CHAR_BIT__ != 8
#error Only 8 bits character is supported
#endif
#if __SIZEOF_INT__ != 4
#error Only 4 bytes integer is supported
#endif
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
#error Only Little Endian is supported
#endif
union myconv_t {
unsigned n;
unsigned char a[4];
};
void
myconv (const union myconv_t *in, int out[4]) {
out[0] = (*in).a[3];
out[1] = (*in).a[2];
out[2] = (*in).a[1];
out[3] = (*in).a[0];
}
int
main (void) {
int example = 0x12345678;
int conv[4];
myconv ((union myconv_t *)&example, conv);
printf ("%x => %x %x %x %xn", example, conv[0], conv[1], conv[2], conv[3]);
printf ("%o => %o %o %o %on", example, conv[0], conv[1], conv[2], conv[3]);
printf ("%d => %d %d %d %dn", example, conv[0], conv[1], conv[2], conv[3]);
return 0;
}