c# - 在 C# 中将 byte 转换为 bool

标签 c# arduino rfid raspberry-pi2 windows-10-iot-core

我正在尝试基于 arduino 库(http://blog.electrodragon.com/rc522-write-a-card-demo-code/)在 c# 上创建一个物联网核心库,但我不明白什么是:

if (!(temp & 0x03))

while ((i!=0) && !(n&0x01) && !(n&waitIRq))

它是必需的 bool 值,但它们是字节! 我如何转换它?

如果有人知道已经创建的库,请告诉我。 谢谢。

最佳答案

在 C 中,任何非零表达式隐式为真,零为假。在 C# 中,您需要进行显式比较:

if ((temp & 0x03) == 0)

while ((i!=0) && (n&0x01)==0 && (n&waitIRq)==0)

或者,您可以使用 the .NET's Boolean structure :

bool isTempAppropriate = (temp & 0x03) == 0;
if(isTempAppropriate) { ... }

请注意,bool 只是 System.Boolean 的语法糖,您可以使用 the var keyword而不是 bool

关于c# - 在 C# 中将 byte 转换为 bool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389662/

相关文章:

c# - 在 C# 中将 OracleDataReader 导出到 Excel

c# - output 子句返回值但 executescalar 在 c# 中返回 null

Android NFC 读取 ISO15693 RFID 标签

open-source - 适用于Windows,Linux和Mac的RFID软件

c++ - 将 1's and 0' 的数组值转换为二进制

java - 使用 sendBroadcast 并执行操作 "android.rfid.INPUT"

c# - 即时创建 Excel 文件并将其下载/保存在客户端

c# - 如何从同一对象的构造函数中调用不同的构造函数?

unity-game-engine - 我的电机在 Arduino 上运行速度非常慢

arduino - arduino扩展板与10针之间的冲突