Rate This Document
Findability
Accuracy
Completeness
Readability

Data Deviation Caused by Endianness

Symptom

Data deviation is found during a test.

Cause

Analyze the data deviation. The test data is an integer. The normal value is 31 (00000000 00011111) and the corresponding deviation value is 7936 (000011111 00000000). Data is consistent after big and little endian conversion, and the code ran on the PowerPC (big endian mode by default).

Procedure

  1. Modify the code to include endian conversion and implement the endian conversion macro of the short type.
     #define SWAP16(x) ((((x)& 0xFF00) >> 8) | (((x)& 0xFF00) << 8))
  2. Compile the array for the endian conversion.
     for(int i = 0;i < RESOLUTION_SIZE;i++){
    	short tmp = *(pIsmDppsDem50km + i);
    	tmp = SWAP16(tmp);
    	*(pIsmDppsDem50km + i) = tmp;
     }