我如何检查,如果掩码包含位? [英] How do I check, if bitmask contains bit?

查看:86
本文介绍了我如何检查,如果掩码包含位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白这整个概念位掩码

I don't quite understand this whole bitmask concept.

让我们说我有一个面具:

Let's say I have a mask:

var bitMask = 8 | 524288;

我已了解,这是我怎么会结合 8 524288 ,并获得 524296

但我怎么走另一条路?如何查看我的掩码,看它是否包含 8 和/或 524288

BUT, how do I go the other way? How do I check my bitmask, to see if it contains 8 and/or 524288?

要使它更复杂一点,让我们说的掩码我是 18358536 ,我需要检查 8 524288 在该位掩码。如何在地球上我要这么做?

To make it a bit more complex, let's say the bitmask I have is 18358536 and I need to check if 8 and 524288 are in that bitmask. How on earth would I do that?

推荐答案

以及

if (8 & bitmask == 8 ) {
}

将检查掩码包含8个。

will check if the bitmask contains 8.

更复杂的

int mask = 8 | 12345;
if (mask & bitmask == mask) {
}

可通过枚举感兴趣的更特别的FlagsAttibute.

这篇关于我如何检查,如果掩码包含位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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