mirror of
https://github.com/Hizenberg469/C1-Linux_SYS_Prog-AS-.git
synced 2026-04-19 18:32:24 +03:00
machine endianess
This commit is contained in:
14
endianess/Makefile
Normal file
14
endianess/Makefile
Normal file
@@ -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
|
||||||
30
endianess/endian.c
Normal file
30
endianess/endian.c
Normal file
@@ -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;
|
||||||
|
}
|
||||||
26
endianess/endian.h
Normal file
26
endianess/endian.h
Normal file
@@ -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
|
||||||
BIN
endianess/endian_exe
Executable file
BIN
endianess/endian_exe
Executable file
Binary file not shown.
33
endianess/main.c
Normal file
33
endianess/main.c
Normal file
@@ -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 <stdio.h>
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
int val = machine_endianness_type();
|
||||||
|
|
||||||
|
if( val ){
|
||||||
|
printf("Little endian machine\n");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
printf("Bit endian machine\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user