/* C program to set and clear bits of a number.*/
#include <stdio.h>
int main(){
int a = 10; // 0x0A
a=a ^ (1<<0); // | or &
printf("%d",a);
}
#include <stdio.h>
int main()
{
unsigned int num = 0x0C;
/*set 0th and 1st bits*/
num |= (1 << 0); /*set 0th bit*/
num |= (1 << 1); /*set 1st bit*/
printf("\nValue of num = %04X after setting 0th and 1st bits.", num);
/*clear 0th and 1st bits*/
num &= ~(1 << 0); /*set 0th bit*/
num &= ~(1 << 1); /*set 1st bit*/
printf("\nValue of num = %04X after clearing 0th and 1st bits.", num);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: