如何将 int 转换为 bool 数组(表示整数中的位)?例如:
4 = { true, false, false }
7 = { true, true, true }
255 = { true, true, true, true, true, true, true, true }
最佳答案
int
应该很好地映射到 BitVector32
(或 BitArray
)
int i = 4;
var bv = new BitVector32(i);
bool x = bv[0], y = bv[1], z = bv[2]; // example access via indexer
但是,就我个人而言,我只是使用轮类(>>>
等)并将其保留为 int
。 bool[]
会大得多
关于c# - 如何将 int 转换为 bool 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4448063/