Q:

C program to swap two words/bytes.

0

C program to swap two words/bytes.

This program will swap two bytes/words of an integer number, here this operation is implemented using bitwise shifting and bit masking.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Swapping two Bytes/Words using C program

/* C program to swap bytes/words of integer number.*/

#include <stdio.h>

int main()
{
    unsigned int data = 0x1234;
    printf("\ndata before swapping : %04X", data);

    data = ((data << 8) & 0xff00) | ((data >> 8) & 0x00ff);

    printf("\ndata after swapping  : %04X", data);

    return 0;
}
    data before swapping : 1234
    data after swapping  : 3412

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C solved programs/examples on Bitwise Operators

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to check whether all bits of a number ar... >>
<< C program to reverse bits of an integer number....