0
protected boolean[] bitArray = new boolean[8];

protected void readNextByte() throws IOException {

    latestReadByte = reader.read();
    int decimtalTal = latestReadByte

    for(int n= 0; n < 8; n++){
        int pos = (int)Math.pow(2, n);

        bitArray[7-n] = (decimalTal & pos) == pos;  // THIS LINE

        // what is the bitwise And in bracket == pos supposed to mean?
    }
}
4

2 回答 2

2

赋值右侧的代码bitArray[7-n] =正在测试是否n设置了 decimalTal 位。如果该位被设置(非零),它评估为真,如果该位被清除(零),则为假。

于 2013-03-04T01:48:49.350 回答
0

@VGR 是正确的,但是当您将来遇到类似代码时要指出一个小细节:

(decimalTal & pos) == pos 测试pos 中的所有位是否也设置为 decimalTal

(decimalTal & pos) != 0 测试pos 中的任何位是否也设置为 decimalTal

在这个例子中,pos 只设置了 1 位,因为它是 2 的幂,所以没关系。

于 2013-03-04T02:02:07.607 回答