布尔数组或字符串,用于在Java Embedded System中存储位字符串

时间:2019-05-23 17:40:21

标签: java embedded

要将位字符串存储在运行于对性能至关重要的嵌入式系统中的Java程序中并最大程度地减少资源的使用,是使用布尔数组还是字符串更好?

1 个答案:

答案 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);
}

}