Tuesday, July 10, 2012

Write a program to compute the endianness of a system

Endianess
In computing, the term endian or endianness refers to the ordering of individually addressable sub-components within the representation of a larger data item as stored in external memory (or, sometimes, as sent on a serial connection). A big-endian machine stores the most significant byte first, and a little-endian machine stores the least significant byte first.

The solution:-
#include <iostream>
using namespace std;

int main()
{
    short int i = 0x0001;
    char* b = (char *)&i;
    if ( b[0] )
        cout << "Little Endian" << endl;
    else
        cout << "Big Endian" << endl;

    return 0;
}


Output on Windows:-
Little Endian

0 comments :

Post a Comment

Contact Form

Name

Email *

Message *

Back to Top