C ++ is determined calculation formula storage mode is big-endian or little-endian mode storage

Storing small end: in the low byte bit address space, High Byte upper byte of data stored in the low byte address space for storing data.

Big-endian is stored: the high byte bit address space, the high byte and a low byte data stored in the low byte address space for storing data.

 

Determine whether the computer is the heart of a little endian or big endian:

1, taken int type stored in the low byte char, in contrast to the low value of the data extracted with the stored data of the whole type int.

2, with the Commonwealth, according to the characteristics of all members of the shared memory space.

 

// the try a the try 

void judgeSystemEndian () 
{ 
    int A = 0x1234 ;
     char B = static_cast < char > (A);
     IF (B == 0x12 ) 
    { 
        COUT << " This computer is ___" big-endian "storage ___ mode. " << endl; 
    } 
    the else  IF (B == 0x34 ) 
    { 
        COUT << " this computer is ___ "little endian" ___ storage mode. " << endl; 
    } 

    Union the U- 
    { 
        intA;
         char B; 
    } U; 
    UA = . 1 ;
     IF (UB == 0 ) 
    { 
        COUT << " This computer is ___" big-endian "___ storage mode. " << endl; 
    } 
    the else  IF (UB == . 1 ) 
    { 
        COUT << " this computer is ___" little endian "___ storage mode. " << endl; 
    } 
} 

// my computer is little-endian

 

Guess you like

Origin www.cnblogs.com/azbane/p/11303463.html