Google
 

Tuesday, October 09, 2007

Procedure to identify the machine is little endian or big endian

#include <stdio.h>
#include <stdlib.h>
/*
 Procedure to identify the machine is
 little endian or big endian
*/

// Using
// Compile it and run it on the target machine which you want to check.

typedef unsigned char* byte_pointer;

int is_little_endian()
{
    int test = 0x0000FFFF;
    int i;
    byte_pointer p = (byte_pointer)&test;
    return p[0] == 0xFF;
}

int main(int argc, char* argv[])
{
    printf("Current machine is%slittle endian \n",is_little_endian()? " ":"not");
    system("PAUSE");
    return 0;
}

--
Happy day, happy life!

No comments: