-
Notifications
You must be signed in to change notification settings - Fork 34
BitOrdering
SeparateWings edited this page Jul 8, 2023
·
2 revisions
There are two bit ordering mode
- LSB0 - the least significant bit is the bit 0, it is the default Java mode and JBBP uses the mode by default
- MSB0 - the most significant bit is the bit 0
JBBP allows both the mode but it should be defined once before operations over parsing or packing operations, the mode is provided by com.igormaznitsa.jbbp.io.JBBPBitOrder enum which contains predefined values. To define the bit order for parsing operations, you can just define the bit order during a parser preparation, like as in the example:
JBBPParser.prepare("byte;", JBBPBitOrder.MSB0);
For pack operations you can send the value through a BeginBin() command of the DSL:
JBBPOut.BeginBin(JBBPBitOrder.MSB0).Int(512).End().toByteArray();
Just remember that the bit ordering can be defined only once before operations and it is impossible to parse block field with different bit order for each field.