text: How to swap two bits in a given integer ? | C code for swapping given bits of a number ; left - shift 1 p1 and p2 times and using XOR ; Driver Code
code: #include <stdio.h> NEW_LINE int swapBits ( int n , int p1 , int p2 ) { n ^= 1 << p1 ; n ^= 1 << p2 ; return n ; } int main ( ) { printf ( " Result ▁ = ▁ % d " , swapBits ( 28 , 0 , 3 ) ) ; return 0 ; }