如何使用逻辑运算符来确定是否设置了一个位,或者移位是唯一的方法?
我发现这个问题使用位移,但我认为我可以AND
发挥我的价值。
在某些情况下,我正在从 Active Directory 中读取一个值并尝试确定它是否是架构基础对象。我认为我的问题是语法问题,但我不知道如何纠正它。
foreach (DirectoryEntry schemaObjectToTest in objSchema.Children)
{
var resFlag = schemaObjectToTest.Properties["systemFlags"].Value;
//if bit 10 is set then can't be made confidential.
if (resFlag != null)
{
byte original = Convert.ToByte( resFlag );
byte isFlag_Schema_Base_Object = Convert.ToByte( 2);
var result = original & isFlag_Schema_Base_Object;
if ((result) > 0)
{
//A non zero result indicates that the bit was found
}
}
}
当我查看调试器时:
resFlag
是一个object{int}
并且值是0x00000010
。
isFlag_Schema_Base_Object
, 是0x02