Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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
使用CCS读取位置&;使用编码器的电机速度。请解释以下语法_C_Pointers_Syntax_Encoder - Fatal编程技术网

使用CCS读取位置&;使用编码器的电机速度。请解释以下语法

使用CCS读取位置&;使用编码器的电机速度。请解释以下语法,c,pointers,syntax,encoder,C,Pointers,Syntax,Encoder,请用C语言解释以下语法 语法-变量名称&=0xFFF(十六进制值) 代码如下所示 // The following lines calculate // // p->thetaMech ~= QPOSCNT / mechScaler [current cnt/(total cnt in 1 rev)] // // where mechScaler = 4000 cnts/revolution // temp = (int32_t)p->thetaRaw * (int32_t)p-&g

请用C语言解释以下语法

语法-变量名称&=0xFFF(十六进制值)

代码如下所示

// The following lines calculate
//
// p->thetaMech ~= QPOSCNT / mechScaler [current cnt/(total cnt in 1 rev)]
//
// where mechScaler = 4000 cnts/revolution
//
temp = (int32_t)p->thetaRaw * (int32_t)p->mechScaler;   // Q0 * Q26 = Q26
temp &= 0x03FFF000;

p->thetaMech = (int16_t)(temp >> 11);                    // Q26 -> Q15
p->thetaMech &= 0x7FFF;

@TomKarzes完全正确。作为补充资料。
是按位
运算符。简单地说,在
二进制形式中添加2个值
,两个都有位1的位置保持为1,在所有其他情况下,它变为0。例如:

Bitwise AND &

  11001000 // decimal: 200  hexadecimal: 0xC8
& 10111000 // decimal: 184  hexadecimal: 0xB8
  -------- 
= 10001000 // result decimal: 136 hexadecimal: 0x88

C中的
op=
运算符使用左侧作为赋值目标和相应操作的第一个操作数。例如,
a+=2相当于
a=a+2。在您的例子中,
a&=b相当于
a=a&b