Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program tests the endian of your system
- */
- #include <stdio.h>
- #include <stdint.h>
- union byte_order {
- uint32_t dword;
- uint8_t bytes[4];
- };
- int main(void)
- {
- int i;
- union byte_order dw = {
- .dword = 0xAABBCCDD,
- };
- printf("Assigned 0x%X\nRepresented by 0x", dw.dword);
- for (i = 0; i < 4; i++) /* 4 is the sizeof(uint32_t) */
- printf("%X", (unsigned char)dw.bytes[i]);
- putchar('\n');
- if (dw.bytes[0] == (uint8_t)0xAA)
- puts("Your system is BIG ENDIAN");
- else if (dw.bytes[0] == (uint8_t)0xDD)
- puts("Your system is LITTLE ENDIAN");
- else
- puts("I can't tell what your system is...");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment