逻辑和问题? [英] Logical AND problem ?

查看:61
本文介绍了逻辑和问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有点Bizzar的问题,但我有一些数据,我必须合乎逻辑''&''戴着面具

允许正确读取数据。问题在下面的代码中

Hi All,

Bit of Bizzar question but I have some data that I have to logical ''&'' with a mask
to allow the data to be read off correctly. The issue is in the below code

//Status (bit 4 Status) – if bit 4 = 0 then ‘False’ else ‘True’
            if ((Hexvalue2 & 0x0008) == 0)
            {
                MessageBox.Show("hello bit 4 not set");
                //checkBox4.Checked = false;
                label10.Text = " Status-";
               label9.Text += "False";
            }
            else
            {
                MessageBox.Show("bit 4 set");
                //checkBox4.Checked = true;
                label10.Text = "Status-";
                label9.Text += "True"; 
            }



我很确定这是正确的,因为我正在做正确的事情,因为我在其他地方做了类似的成功,这意味着该位在字节中设置我正在读书。我现在头上有一个巨大的问号,我正在测试我不是吗?



格伦


I am pretty sure this is correct as I am doing it right as I have done similar elsewhere with success which means the bit is set in the byte I am reading in. I now have a giant question mark over my head, I am testing properly am I not?

Glenn

推荐答案

不完全。

首先,&是二进制AND而不是逻辑AND - 后者是&&。

其次,0x0008没有第4位设置 - 它有第3位设置:

Not quite.
First off, "&" is a binary AND not a logical AND - the latter is "&&".
Secondly, 0x0008 does not have bit 4 set - it has bit 3 set:
Bit No  Hex   Decimal
 0       01       1
 1       02       2
 2       04       4
 3       08       8
 4       10      16
 5       20      32
 6       40      64
 7       80     128


很难知道发生了什么在这里。

有可能你的第4位实际上是第五位(如果你从0开始计数);在这种情况下,第4位掩码将是0x0010而不是0x0008。

但这只是猜测。无论如何,我的测试方法似乎没有什么问题。
Hi, it''s quite hard to know what is going on here.
Could it be possible that your bit 4 is in fact the fifth (if you start counting at 0) ; in this case, bit 4 mask would be 0x0010 and not 0x0008.
But it''s just a guess. Anyway, nothing seems wrong to me in your testing method.


这篇关于逻辑和问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆