Friday, July 9, 2021

Little and Big Endian

 Little and big endian are two ways of storing multibyte data-types.



Suppose integer is stored as 4 bytes then a variable x with value 0x01234567 will be stored as following in Big Endian

Big Endian:

  01,                   23,                45,             67

 0x100             0x101            0x102         0x103


Little Endian

 67,                   45,                23,             01

 0x100             0x101            0x102         0x103


Sample C program to check this.,


int main() 
    unsigned int i = 1; 
    char *c = (char*)&i; 
    if (*c) 
        cout<<"Little endian"
    else
        cout<<"Big endian"
    return 0; 

No comments:

Post a Comment