我对低级操作这样的东西还是很陌生的,希望有人能指出我在这里可能犯的明显错误。
//Input value - 00111100
//I want to get the value of the bits at indexes 1-3 i.e 0111.
byte mask = (byte)0x00001111; // This gives 17 not the 15 I'd expect
byte shifted = (byte)(headerByte >> 3);
//shifted is 7 as expected
byte frameSizeValue = (byte)(shifted & mask); //Gives 1 not 7
看起来问题在于掩码的定义方式,但我不知道如何修复它。