Tuesday, July 10, 2012

Write a program to compute the endianness of a system

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;
        cout << "Big Endian" << endl;

    return 0;

Output on Windows:-
Little Endian


Post a Comment

Contact Form


Email *

Message *

Back to Top