0

I need to write a small C program to demonstrate that the UNIX operating system is using Big Endian, and the MS-Windows/DOS system is using Little Endian. I'm having trouble putting my thoughts into code (beginner coder) but I'm assuming I can load a 32 bit word into an address and just check where the LSB is, but then again I'm still a beginner.

Can anyone help me out?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
user2819756
  • 51
  • 1
  • 5
  • 2
    possible duplicate of [C program to check little vs. big endian](http://stackoverflow.com/questions/12791864/c-program-to-check-little-vs-big-endian) – Étienne Sep 26 '13 at 13:48

1 Answers1

3
#include <stdio.h>

int main() 
{
   unsigned int i = 1;

   char *c = (char*)&i;

   if (*c) {  
       printf("Little endian");
   } else {
       printf("Big endian");
   }

   getchar();

   return 0;
}
Roy Dictus
  • 32,551
  • 8
  • 60
  • 76