binary math is hard
This commit is contained in:
parent
6453e891e6
commit
b72b73373f
|
@ -48,7 +48,7 @@ public class EnumIniField extends IniField {
|
|||
|
||||
public static int getBitRange(int ordinal, int bitPosition, int bitSize) {
|
||||
ordinal = ordinal >> bitPosition;
|
||||
ordinal = ordinal & (1 << bitSize);
|
||||
ordinal = ordinal & ((1 << (bitSize + 1)) - 1);
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,11 @@ public class IniFileReaderTest {
|
|||
|
||||
@Test
|
||||
public void testBitLogic() {
|
||||
assertEquals(4, EnumIniField.getBitRange(4, 0, 7));
|
||||
assertEquals(4, EnumIniField.getBitRange(4, 0, 2));
|
||||
assertEquals(0, EnumIniField.getBitRange(4, 0, 1));
|
||||
assertEquals(3, EnumIniField.getBitRange(7, 0, 1));
|
||||
|
||||
assertEquals(1, EnumIniField.getBitRange(0xff, 0, 0));
|
||||
|
||||
assertEquals(1, EnumIniField.getBitRange(0xf0, 4, 0));
|
||||
|
|
Loading…
Reference in New Issue