繁体   English   中英

将一些操作从javascript转换为c#— if(int&#)

[英]Translating some bit operations from javascript to c# — if(int & #)

所以我将一些java转换为c#,这是一个示例位

// bits = 12 bit number
int bits = table[index];

if (bits & 1)
{...}

if (bits & 2)
{...}

if (bits & 3)
{...}

ect

位和#位错误是由于

Cannot implicitly convert type 'int' to 'bool'

我了解错误,我只是不确定如何将位和#位转换为C#安全代码,有人知道应该怎么做吗?

谢谢。

轻松,只需将结果与0进行比较即可。

一些基于C的语言将0视为false,将其他值视为true。 但这对于C#而言并非如此

if ((bits & 2) !=0 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM