位操作-解释下面的c++代码部分
bit manipulation - Explain the following C++ code part
//class start--
//Global variable
static PMSK *savepr;
static PRC *prs;
//inside some method
static PMSK wkpm;
PMSK *pm;
if (ipf) {
k = to_bits(312, &msk); // This will return k=24 and msk =char(00000001),
if ( pm->orbits[k] & msk ) // See the answer of my previous question.
prs[i].pccused = 1;
}
关于to_bits方法,请参见链接
解释下面的c++方法
我不熟悉c++编程。第二个if块中发生了什么?解释一下变量声明?
谢谢
如果我理解正确的话,您是想了解if
-clause:
if ( pm->orbits[k] & msk )
包含位与运算符,该运算符取pm->orbits[k]
的位和msk
的位,并返回两个值中的位(即"与"部分)。
:
0010 1101 &1010 1010 = 0010 1000
我建议你读一本好的c++初学者书籍来学习指针(->
)和数组([k]
)。
因为你没有给出关于PMSK类型的信息,我不知道mp->orbits[k]
会给你什么,除了这个:PMSK结构或类似乎包含一个名为轨道的数组,pm->orbits[24]
表示它的第25个(不是第24个!)元素。
if ( pm->orbits[k] & msk ) // check to see if they aare bit-by-bit identical.
变量声明是如何进行的?我不明白你的意思,请说清楚。
class start--
语法无效。
static PMSK *savepr;
static PRC *prs;
这些指针指向具有内部链接的PMSK, PRC类型的对象。
static PMSK wkpm;
PMSK *pm;
具有内部链接的PMSK对象实例和指向具有平移单位作用域的PMSK对象"wkpm"的指针。
if(ipf){
k = to_bits(312, &msk); // you might want to post this "to_bits" function
if ( pm->orbits[k] & msk ) // this returns the k+1 object in the array "orbits" and performs a bitwise AND with "msk"
// you might want to post the declaration for this pm instance and the class decaration
prs[i].pccused = 1; // this sets the member variable "pcussed" of object i + 1 in the array "prs" to 1
}
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 代码在main()中运行,但在函数中出现错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 编译包含字符串的代码时遇到问题
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 在Linux for Windows上编译C++代码时出错
- 我的字符计数代码计算错误.为什么
- 孤立代码块在结构中引发异常
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 此代码是否违反一个定义规则
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 为什么在这个代码结束循环中没有得到结束
- 不知道为什么代码只打印第一部电影
- cpp 文件中的部分行最终出现在输出文件中 - 闹鬼的代码