Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 位运算符比较错误_C_Macros_Arm_Bit_Iar - Fatal编程技术网

C 位运算符比较错误

C 位运算符比较错误,c,macros,arm,bit,iar,C,Macros,Arm,Bit,Iar,编译程序:IAR 平台:stm32f4 我有这个代码,但它不工作的预期。 有人能解释为什么 #define byteGetbit(x,y) ((x) & (0x01 << (y))) volatile t_uint8 test=0xFF; if(byteGetbit(test,0x03)==1){ //always false printf("hello"); //can't reach the code here test = 0; } byteGetbit

编译程序:IAR 平台:stm32f4

我有这个代码,但它不工作的预期。 有人能解释为什么

#define byteGetbit(x,y) ((x) & (0x01 << (y)))

volatile t_uint8 test=0xFF;
if(byteGetbit(test,0x03)==1){ //always false
   printf("hello"); //can't reach the code here
   test = 0;
}

byteGetbit
生成一个具有相应位集或清除的值,因此要测试位集,您必须检查:

if(byteGetbit(test,0x03) == 0x03)


byteGetbit
生成一个具有相应位集或清除的值,因此要测试位集,您必须检查:

if(byteGetbit(test,0x03) == 0x03)


byteGetbit
生成一个具有相应位集或清除的值,因此要测试位集,您必须检查:

if(byteGetbit(test,0x03) == 0x03)


byteGetbit
生成一个具有相应位集或清除的值,因此要测试位集,您必须检查:

if(byteGetbit(test,0x03) == 0x03)


((x)和(0x01
((x)和(0x01
((x)和(0x01
)((x)和(0x01)您不读取位,但在其当前位置隔离位

您应该将byteGetbit更改为:

#define byteGetbit(x,y) ((x >> y) & 0x01)

这会将位移到位0,然后将其隔离。

您不会读取位,但会将位隔离在其当前位置

您应该将byteGetbit更改为:

#define byteGetbit(x,y) ((x >> y) & 0x01)

这会将位移到位0,然后将其隔离。

您不会读取位,但会将位隔离在其当前位置

您应该将byteGetbit更改为:

#define byteGetbit(x,y) ((x >> y) & 0x01)

这会将位移到位0,然后将其隔离。

您不会读取位,但会将位隔离在其当前位置

您应该将byteGetbit更改为:

#define byteGetbit(x,y) ((x >> y) & 0x01)

这将把位移到位0,然后将其隔离。

printf(“%d\n”,byteGetbit(test,0x03));
@user1111998您的逻辑
if(byteGetbit(test,0x03)==1)
定义byteGetbit(x,y)((x)和(0x01
printf(“%d\n”,byteGetbit(test,0x03));
@user1111998您的逻辑
if(byteGetbit(test,0x03))=1)
#定义byteGetbit(x,y)((x)和(0x01
printf(“%d\n”,byteGetbit(test,0x03));
@user1111998您的逻辑
如果(byteGetbit(test,0x03)==1)
定义byteGetbit(x,y)((x)和(0x01
printf(“%d\n”,byteGetbit(test,0x03));
@userif(byteGetbit,test
#定义字节位(x,y)((x)和(0x01