C program to swap two bits of a byte
Given a byte (an integer number of 8 bits) and we have to swap its any two bits using C program.
In this program, we declared an unsigned char type variable to read 8 bits number (byte) and we are swapping two bits (1 and 2) of given number.
Example:
Input number: 0x0A (Hexadecimal)
Binary of input number: 0000 1010
After swapping of bit 1 and 2
Binary will be: 0000 1100
Output number will be: 0x0C (Hexadecimal)
Swapping two bits of a byte using C program
Output
need an explanation for this answer? contact us directly to get an explanation for this answer