我是这样的低级操作的新手,我希望有人能指出我在这里必须犯的明显错误。
//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
看起来问题出在定义掩码的方式上,但我不知道如何修复它。