#define CLEAR_BIT(value, pos) value &= ~(1U<< pos)
#define TOGGLE_BIT(value, pos) value ^= (1U<< pos)
#define CHECK_BIT_IS_SET_OR_NOT(value, pos) value & (1U<< pos)
Let see an example to set the bit using the above macro,
#include <stdio.h>
#define SET_BIT(value, pos) value |= (1U<< pos)
int main()
{
//value
unsigned int value =0;
//bit position
unsigned int pos = 0;
printf("Enter the value\n");
scanf("%d",&value);
printf("Enter the position you want to Set\n");
scanf("%d",&pos);
SET_BIT(value,pos);
printf("\n\n%dth Bit Set Now value will be = 0x%x\n",pos,value);
return 0;
}
Let see an example to set the bit using the above macro,
Output:
Enter the value
5
Enter the position you want to Set
1
1th Bit Set Now value will be = 0x7
need an explanation for this answer? contact us directly to get an explanation for this answer