Created
December 9, 2011 23:21
-
-
Save k4rtik/1453785 to your computer and use it in GitHub Desktop.
Program to check the endianness of a machine. - January 9, 2011
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* endian.c | |
* Program to check the endianness of a machine. | |
* | |
* Copyright (C) 2011 - Kartik Singhal | |
* | |
* License: GNU General Public License version 3 | |
* | |
*/ | |
#include <stdio.h> | |
int main() | |
{ | |
int num = 0x1451; | |
char* p = (char*) # | |
char* q = p+1; | |
printf("First byte: %x\n", *p); | |
printf("Second byte: %x\n", *q); | |
(*p == 0x51) ? printf("This machine is Little Endian\n") :\ | |
printf("This machine is Big Endian\n") ; | |
return 0; | |
} | |
/* | |
* This program uses some reference from: | |
* http://sites.google.com/site/insideoscore/endianness | |
* and the author wants to acknowledges the same. | |
*/ | |
/* | |
* OUTPUT (on a an Intel Core 2 Duo based machine): | |
******************************************************************************* | |
kartik@PlatiniumLight:~$ gcc endian.c | |
kartik@PlatiniumLight:~$ ./a.out | |
First byte: 51 | |
Second byte: 14 | |
This machine is Little Endian | |
******************************************************************************** | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment