#include <stdio.h>
#define SETPIN(PIN,N) (PIN &= ~(1<<N))
int main(){
unsigned char val = 0xFF;
unsigned char bit = 2;
printf("val = %X\n",val);
//SET bit number 2 to zero
SETPIN(val,bit);
printf("Aftre setting bit %d to zero, val = %X\n", bit, val);
return 0;
}
Output
val = FF
Aftre setting bit 2 to zero, val = FB
Explanation:
In this example, initially the value of val is 0xFF that is "1111 1111" in binary.
To set bit number 2 (i.e. third bit) to zero, when we call macro SETPIN(val, bit), the bit number 2 will set to 0. Thus, the output will be "1111 1011" i.e. 0xFB in Hexadecimal.
Example:
Output
val = FF Aftre setting bit 2 to zero, val = FBExplanation:
- In this example, initially the value of val is 0xFF that is "1111 1111" in binary.
- To set bit number 2 (i.e. third bit) to zero, when we call macro SETPIN(val, bit), the bit number 2 will set to 0. Thus, the output will be "1111 1011" i.e. 0xFB in Hexadecimal.
need an explanation for this answer? contact us directly to get an explanation for this answer