#include <stdio.h>
/*
Program to swap 1st and 2nd bit of hexadecimal value stored in data variable
*/
int main()
{
unsigned char data = 0xA; // Assiging hexadecimal value since 1byte data
// Get 1st bit from data
unsigned char bit_1 = (data >> 1) & 1; // 10100000 -> (01100000) & 00000001
// Get 2nd bit from data
unsigned char bit_2 = (data >> 2) & 1;
// Get XOR of bit_1 and bit_2
unsigned char xor_of_bit = bit_1 ^ bit_2;
printf("After swapping the bits, data value is: %2X", data ^ (xor_of_bit << 1 | xor_of_bit << 2));
int a = 0xA; //1010
int bit1 = (a >> 3) & 1; // it will get the bit by bit value usefull fun
//1010 >> 0001 & 1 //shift position >> entire byte
//if 2 : 1010 >> 0010 & 1 = 0
//if 1 : 1010 >> 0101 & 1 = 1
printf("%d",bit1);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: