Tri*_*ith 5 java bit-manipulation bitmask
我是这样的低级别操作的新手,我希望有人可以指出我必须在这里犯下的明显错误.
//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
Run Code Online (Sandbox Code Playgroud)
看起来问题在于定义掩码的方式,但我看不出如何修复它.