要将位字符串存储在运行于对性能至关重要的嵌入式系统中的Java程序中并最大程度地减少资源的使用,是使用布尔数组还是字符串更好?
答案 0 :(得分:0)
取决于您拥有多少布尔值,我建议使用int
值,因为它可以存储32位值,如果您想获得第3位的值,则可以使用类似以下内容:>
public class Test {
public static void main(String[] args) {
int x=0;
System.out.println((x & 0x04) >> 2);
//set one at 3rd bit
x=x | 0x4;
System.out.println((x & 0x04) >> 2);
//clear the 3rd bit
x=x & 0xfffffffb;
System.out.println((x & 0x04) >> 2);
}
}