------------------------------------------------------------------------------
MC logo
Which Endian Is Up?
[^] Chapter 5: Real-World Architectures
------------------------------------------------------------------------------
[Chapter 1: Introduction] [Chapter 2: Data Representation] [Chapter 3: Boolean Algebra and Digital Logic] [Chapter 4: MARIE: A Very Simple Architecture] [386 Assembler Language] [Chapter 5: Real-World Architectures] [Chapter 6: Memory Systems] [Chapter 7: I/O Systems] [Chapter 9: Alternative Architecture] [Chapter 11: Performance Measurement]
[Which Endian Is Up?]
endian.c
/* This program prints the bytes of a C integer in memory order to show
   if the system is big- or little- endian. */

#include <stdio.h>

main()
{
        int num = 0x78AB12EF;
        int i;
        char *scan;

        printf("0x%X  ", num);
        scan = (char *)&num;
        for(i = 0; i < sizeof num; ++i)
                printf(" %02X", *scan++ & 0x0ff);
        printf("\n");
}