Endianness of ur own Machine !!!

Discussion in 'C' started by batman.pratik, Jun 18, 2008.

  1. batman.pratik

    batman.pratik New Member

    Joined:
    Jun 18, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Q. Write a program to identify the endianness of the machine you are working on.

    Can anyone please tell me how to do it !!!
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    3
    Trophy Points:
    0
    Here is the code.
    Code:
    bool is_bigendian()
    {
    	int i = 1;
    	char *ptr = (char*)&i;	// Assign into 1 byte pointer
    	return (*ptr == 0);	// Check if the 1 Byte is not having the value 1 which is assigned
    }
     
  3. batman.pratik

    batman.pratik New Member

    Joined:
    Jun 18, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Sorry, couldn't get that. Will u plz explain it properly. !!!
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    3
    Trophy Points:
    0
    Its a couple of lines of code where each line is well explained.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice