如何编写一个程序,将 001010101110000100100
...., 011100010001000011000
...., 000000000010000000000100
.... 作为输入(位)和输出将是这 3 个的 OR
。
OR = 0 0 = 0,
0 1 = 1,
1 0 = 1,
1 1 = 1,
如果某人有一个示例程序也会有帮助。我们是否需要将字节中的值存储在位数组中?
最佳答案
您不能只调用 or
method in the BitSet class 吗? ?
[edit] 假设你想要一个例子,像这样的东西应该可以工作:
BitSet doOr( List<BitSet> setsToOr ) {
BitSet ret = null ;
for( BitSet set : setsToOr ) {
if( ret == null ) {
// Set ret to a copy of the first set in the list
ret = (BitSet)set.clone() ;
}
else {
// Just or with the current set (changes the value of ret)
ret.or( set ) ;
}
}
// return the result
return ret ;
}
关于java - Java中的或运算(BitSet.class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244761/