frysk.value
Class Packing
java.lang.Object
frysk.value.Packing
class Packing
- extends Object
Utility methods for packing and unpacking BigInteger bit-fields
from a big-endian byte[] buffer.
Constructor Summary |
Packing(int size,
int bitOffset,
int bitLength)
Create a packing object. |
signBit
private final int signBit
shift
private final int shift
mask
private final BigInteger mask
Packing
Packing(int size,
int bitOffset,
int bitLength)
- Create a packing object. SIZE is the byte size of the value
containing the bit field. BIT_SIZE is the number of bits in
the packed field. BIT_OFFSET is the number bits to the right
of the packed field
toString
public String toString()
- Overrides:
toString
in class Object
pack
byte[] pack(byte[] buffer,
BigInteger value)
- Pack VALUE into the byte buffer.
Note that the returned byte[] buffer may differ in length from
the original: leading zeros will be stripped (e.g.,
byte[]{000,0x01} becomes byte[]{0x01}); and any leading large
unsigned byte will be prefixed with a zero (e.g., byte[]{0xff}
becomes byte[]{0x00,0xff}). The client may need to truncate or
zero extend as necessary.
Since the receiving method Location.put(ByteOrder,byte[],int)
(with zero fill) used to store the packed result handles all
this correctly, this is not normally a problem.
unpackSigned
BigInteger unpackSigned(byte[] buffer)
- Unpack the value as a signed.
unpackUnsigned
BigInteger unpackUnsigned(byte[] buffer)