|
unpack
Syntax:
#include <boost/bit_logic/bit_container_type.hpp> PackT unpack <PackT> ( size_type upper_bit_idx, size_type lower_bit_idx ) ; PackT unpack <PackT,EncodingT> ( size_type upper_bit_idx, size_type lower_bit_idx ) ; Template Arguments :
Note: These functions are equivelant for all bit_container types. bit_array<N>, bit_vector, bit_container_adaptorUnpack function decodes a series of bits within a Bit Container as a given type and returns it. TODO: Make this not look exactly like pack or merge them. For example:
bit_array<10> a ;
enum color { red = 0, green = 1, blue = 2, pink = 22 } ;
a.unpack( red, 1, 0 );
color my_color = a.ununpack<color> ( 1, 0);
This above code allows for an enumerated type to be represented in 2 bits. The value 0 can be represented by 2 bits, and v.unpack( pink, 2, 0); This code throws an exception as the binary value of 22 : 10110 requires a minimum of 5 bits to be represented fully. This container adheres to the strict guarantee and no data within v has been harmed by the attempt to unpack data that would overflow into it. uint32_t my_uint = 42 ; /// 101010 binary representation a.unpack( my_uint, 8, 3 ) ; uint32_t another_uint = a.ununpack>uint32_t< (9,3); This code unpacks the 32 bit unsigned integral type of value 42 into the most significant 7 bits of a. The value requires a minmum of 6 bits to be precisely represented within that bit range. Signed integral bit representation within a bit_container is defaulted to 2's complement. int32_t my_int = -1 ; a.unpack( my_int, 8, 0 ) ; cout << a << endl ; This will print out : 111111111 a.unpack<signed_magnitude>( my_int, 8, 0 ) ; cout << a << endl ; This will print out : 100000001 unpack can throw any of the following exceptions. Exceptions:
|