![](/img/trans.png)
[英]Unsure how this piece of code is doing what it does… .getDescribe()
[英]What exactly is the last piece of code doing?
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?
}
}
bitArray[7-n] =
賦值右側的代碼正在測試是否設置了decimalTal的位n
。 如果該位置1(非零),則計算結果為true;如果該位清零(零),則計算結果為假。
@VGR是正確的,但是當你在將來遇到類似的代碼時指出一個小的微妙:
(decimalTal & pos) == pos
測試pos中的所有位是否也設置為decimalTal
(decimalTal & pos) != 0
測試pos中的任何位是否也設置為decimalTal
在這個例子中,pos只有1位設置,因為它是2的冪,所以沒關系。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.