加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何读取字节数组中的单个BIT?

发布时间:2020-12-15 19:31:36 所属栏目:百科 来源:网络整理
导读:问题是我有一个带有200个索引的Byte数组,只想检查MyArray [75]的第四位是零(0)还是一(1). byte[] MyArray; //with 200 elements//check the fourth BIT of MyArray[75] 解决方法 元素75中的第四位? if((MyArray[75] 8) 0) // bit is onelse // bit is off
问题是我有一个带有200个索引的Byte数组,只想检查MyArray [75]的第四位是零(0)还是一(1).

byte[] MyArray; //with 200 elements

//check the fourth BIT of  MyArray[75]

解决方法

元素75中的第四位?

if((MyArray[75] & 8) > 0) // bit is on
else // bit is off

&运算符允许您使用值作为掩码.

xxxxxxxx = ?
00001000 = 8 &
----------------
0000?000 = 0 | 8

您可以使用此方法使用相同的技术收集任何位值.

1   = 00000001
2   = 00000010
4   = 00000100
8   = 00001000
16  = 00010000
32  = 00100000
64  = 01000000
128 = 10000000

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读