Swap little endian to big endian and little endian to big endian

Before going to this tutorial first understand what is endian and it's types. program to find little endian or big endian for a processor.
Strongly recommended to visit this

Program to swap little endian to big endian and little endian to big endian

int swap_Endian ( int number )
{
   int byte0, byte1, byte2, byte3;
   byte0 = (number & 0x000000FF) >> 0;
   byte1 = (number & 0x0000FF00) >> 8;
   byte2 = (number & 0x00FF0000) >> 16;
   byte3 = (number & 0xFF000000) >> 24;
   return ((byte0<<24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0));
}

void main(void) {
    int swapped_value;
    swapped_value = swap_Endian(1);
    return;
}

Video Explanation of this program


No comments:

Post a comment