Program Discussion :: Bitwise Operator
18 / 15
Write an efficient program to check the endianness of the machine
Answer:
#include
#include
using namespace std;
int main ()
{
unsigned int x = 0x76543210;
char *c = (char*) &x;
cout
Asked In ::
Language:
Jyoti Choudhary
15 May, 2017 12:07 AM
import java.util.*;
import java.lang.*;
import java.io.*;
class endianness
{
public static void main(String args[])
{
unsigned int i = 1;
char *c = (char*)&i;
if (*c)
System.out.println("Little endian");
else
System.out.println("Big endian");
}
}
Language:
Shreya
7 Jul, 2017 9:30 AM
#include <stdio.h>
int main ()
{
unsigned int x = 0x76543210;
char *c = (char*) &x;
printf ("*c is: 0x%x\n", *c);
if (*c == 0x10)
{
printf ("Underlying architecture is little endian. \n");
}
else
{
printf ("Underlying architecture is big endian. \n");
}
return 0;
}
Language:
Nikhil
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include<iostream>
using namespace std;
int main ()
{
unsigned int x = 0x76543210;
char *c = (char*) &x;
cout<<"*c is: 0x%x\n", *c);
if (*c == 0x10)
{
cout<<"Underlying architecture is little endian. \n";
}
else
{
cout<<"Underlying architecture is big endian. \n";
}
return 0;
}