|
bit_logic > Concepts > Bit Packing / Unpacking
Bit PackingC++ integral data types, and enumerations have defined bit values, which can be represented minimally within a Bit Container type. Integral Conversion and Integral Promotion ( 4.3 ISO Std C++ ) clearly define the operations of converting from one type to another, however values that are converted to smaller types do not cause errors. a enumeration value of 256 when converted into an unsigned 8-bit byte will be truncated to 0, silently. ![]() The Bit Logic library does not allow for any silent alteration of data types encoding with Bit Container types. All values are checked to guarantee their bit pattern can accurately be represented within the given bit sequence, and exceptions are thrown when they cannot be. Signed integral values less than 0 are a special case, as their exact bit representation is not defined by the C++ Standard. The default packing for negative signed integral types is to use a "2's complement" representation. This can be changed by adding a template argument to the member function call, more on signed integrals here. Bit UnpackingUnpacking bits is the corollary to packing bits. It allows for typed data to be extracted from a Bit Container type, and returned by value. The caller is responsible for selecting the correct type information for the given sequence of bits, as no checking ( other than boundary ) checking can be done on the data that is extracted.
|