c语言 宏定义 去除宏定义
Macro definition:
宏定义:
#define SETPIN(PIN,N) (PIN &= ~(1<<N))
Here,
这里,
SETPIN is the Macro name
SETPIN是宏名称
PIN is the value whose bit to set to zero
PIN是其位设置为零的值
N is the bit number
N是位数
Example:
例:
#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.
在此示例中,最初val的值为0xFF ,二进制值为“ 1111 1111” 。
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.
为了将第2位(即第三位)设置为零,当我们调用宏SETPIN(val,bit)时 ,第2位将设置为0。因此,输出将为“ 1111 1011”,即十六进制为0xFB 。
翻译自: https://www.includehelp.com/c-programs/define-a-macro-to-set-nth-bit-to-zero-in-c.aspx
c语言 宏定义 去除宏定义