[C]Program to find whether the given machine is Little Endian or not


/*This program is to test whether the machine Little Endian or not */

#include<stdio.h>
#include <netinet/in.h>

int main (void)
{

unsigned short n=0xABCD;
printf (“%X %X \n”, n , ntohs(n));

return 0;
}

compile the program .

Run the program on the machine which is to be checked

If the output is

ABCD CDAB  then the machine is Little Endian

If the output is

ABCD ABCD then the machine is Big Endian

This program is tested with X86 machine and power pc machine .

 

X86 machine gave the output ABCD CDAB , hence Little Endian

PowerPc machine gave ABCD ABCD, hence Big Endian

Published by RNP

A person who likes learning new languages.

Leave a comment