Search in shivacherukuri.tech@blogger.com

Monday, March 1, 2010

how to find bigendianness

FYI,

int am_big_endian() {

 

 long one = 1;

 printf(" &one :%p \n, (char *)(&one) :%p \n *((char *)(&one)): %c\n", \

          &one, (char *)(&one), (*((char *)(&one))) );

 

 return !(*((char *)(&one)));

}

 

  int am_big_endian2()

  {

      union { long l; char c[sizeof (long)]; } u;

      u.l = 1;

      return (u.c[sizeof (long) - 1] == 1);

  }

 

int main(void) {

 

  printf("Hi..my endianness is\n");

  printf("Big endian = %d \n",am_big_endian2());

  return 0;

}

No comments:

Post a Comment