Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************
- ringneckparrot (c)
- License: http://creativecommons.org/licenses/by-nc-sa/3.0/
- Contact Me:
- Email: ringneckparrot@hotmail.com
- Facebook: http://www.facebook.com/ringneckparrot
- Twitter ID: pp4rr0t
- SecurityTube: http://www.securitytube.net/user/ringneckparrot
- ****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #define LITTLE 0 // LITTLE = Little Endian
- #define BIG 1 // BIG = Big Endian
- int EndiannessTest() //Create a function EndiannessTest() which tests the Endianness and returns an integer (0 for Little Endian | 1 for Big Endian)
- {
- // Declare an integer i and assign a value of 1 to it
- int i = 1;
- // Create a pointer p and make it point to the address of i, we force the compiler to treat it as a character
- char *p = (char *) &i;
- //Check if the value where p points is 1
- if(*p == 1)
- //if yes, it returns the LITTLE (Little Endian) = 0
- return LITTLE;
- else
- //else, it returns the BIG (Big Endian) = 1
- return BIG;
- }
- int main() //Our main() function
- {
- // Create an integer called Endian
- int Endian;
- // Assign Endian with the result of the function EndiannessTest()
- Endian = EndiannessTest();
- //If the result of Endian is LITTLE (= 0), we have a Little Endian system
- if (Endian == LITTLE)
- //We print to the screen "Little Endian", followed by a new line symbol "\n"
- printf("Little Endian\n");
- // If the result of Endian is BIG (= 1), we have a Big Endian system
- if (Endian == BIG)
- //We print to the screen "Big Endian", followed by a new line symbol "\n"
- printf("Big Endian\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement