diff --git a/endianess/Makefile b/endianess/Makefile new file mode 100644 index 0000000..5114fae --- /dev/null +++ b/endianess/Makefile @@ -0,0 +1,14 @@ +TARGET: endian_exe + +endian_exe: main.o endian.o + gcc main.o endian.o -o endian_exe + +endian.o: endian.c + gcc -c endian.c -o endian.o + +main.o: main.c + gcc -c main.c -o main.o + +clean: + rm main.o + rm endian.o diff --git a/endianess/endian.c b/endianess/endian.c new file mode 100644 index 0000000..caea0e4 --- /dev/null +++ b/endianess/endian.c @@ -0,0 +1,30 @@ +/* + * ===================================================================================== + * + * Filename: endian.c + * + * Description: + * + * Version: 1.0 + * Created: 29/02/24 10:13:18 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "endian.h" + +int +machine_endianness_type(){ + + unsigned short int a = 1; + char ist_byte = *((char *)&a); + if( ist_byte == 0 ) + return 0; + else if( ist_byte == 1 ) + return 1; +} diff --git a/endianess/endian.h b/endianess/endian.h new file mode 100644 index 0000000..23961fd --- /dev/null +++ b/endianess/endian.h @@ -0,0 +1,26 @@ +/* + * ===================================================================================== + * + * Filename: endian.h + * + * Description: + * + * Version: 1.0 + * Created: 29/02/24 10:11:52 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#ifndef __ENDIANESS__ +#define __ENDIANESS__ + +/* return 0 - Big endian, 1 for Little endian */ +int +machine_endianness_type(); + +#endif diff --git a/endianess/endian_exe b/endianess/endian_exe new file mode 100755 index 0000000..1fdcde0 Binary files /dev/null and b/endianess/endian_exe differ diff --git a/endianess/main.c b/endianess/main.c new file mode 100644 index 0000000..29cfb32 --- /dev/null +++ b/endianess/main.c @@ -0,0 +1,33 @@ +/* + * ===================================================================================== + * + * Filename: main.c + * + * Description: + * + * Version: 1.0 + * Created: 29/02/24 10:31:18 AM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "endian.h" +#include + +int main(){ + int val = machine_endianness_type(); + + if( val ){ + printf("Little endian machine\n"); + } + else{ + printf("Bit endian machine\n"); + } + + return 0; +}