c++ - 将 if 条件按位转换为通常 if 条件
问题描述
我发现这个 if 条件使用按位,我不知道如何将它转换为使用普通逻辑运算符。
if (out[currentState] & (1 << j))
如何提供不按位使用的等效条件?
解决方案
位移基本上是乘以 2 和除以 2。上述条件等价于
if ((out[currentState] >> j) & 1)
可以转换为
if ((int)(out[currentState] / pow(2, j)) % 2)
推荐阅读
- xamarin.android - 想在“OpenWith”弹出窗口中添加我的 android pkpass 查看器应用程序
- vba - 我可以通过按钮更改同一报告中显示的列吗?
- python - 需要密码等于日期 (d/m/y)
- sql - 如何以智能方式聚合这些行?
- powershell - Invoke-ASCmd 在 PowerShell 中返回错误/警告
- salesforce - 如何在 Salesforce 调查的图像中嵌入 URL?
- javascript - Chrome 将奇怪的矩形渲染成“毛玻璃”效果
- java - Android 项目崩溃
- java - 多个线程何时访问相同的代码?
- r - 为什么 file.exists(tempfile()) 返回 FALSE?