High/Low (Set/Clear) bits of a number using C program
/* C program to set and clear bits of a number.*/
#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;
}
Output:
Value of num = 000F after setting 0th and 1st bits.
Value of num = 000C after clearing 0th and 1st bits.
High/Low (Set/Clear) bits of a number using C program
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer