Main Page   Reference Manual   Compound List   File List  

libecc::bitset< N > Class Template Reference

A bitset with a fixed number of bits. More...

#include <libecc/bitset.h>

Inheritance diagram for libecc::bitset< N >:
Collaboration diagram for libecc::bitset< N >:

List of all members.

Public Member Functions

 bitset (void)
 Construct an uninitialized bitset of N bits.
 bitset (std::string const &)
 Construct a bitset of N bits and initialize it with the string input, a hexadecimal value in ASCII representation.
 bitset (bitset_digit_t low_bits)
 Construct a bitset of which only the least significant bits are set.
 bitset (bitset_digit_t const (&v)[bitset_base< N >::digits])
 Construct a bitset directly from an array of bitset_digit_t.
template<unsigned int m, bool inverted>
 bitset (bitset_invertible< m, inverted > const &)
 Copy constructor.
template<unsigned int m, bool i1, bool i2, typename OP >
 bitset (Operator::bitsetExpression< m, i1, i2, OP > const &expr)
 Construct a bitset from an expression.
template<typename Expression >
bitsetoperator= (Expression const &)
 Assignment operator.
template<typename Expression >
bitsetoperator&= (Expression const &)
 Assignment operator with bitwise AND.
template<typename Expression >
bitsetoperator|= (Expression const &)
 Assignment operator with bitwise OR.
template<typename Expression >
bitsetoperator^= (Expression const &)
 Assignment operator with bitwise XOR.
template<unsigned int shift, class DIRECTION , class OPERATION >
void shift_op (bitset &result) const
 Perform a shift operation followed by a bit operation.
bitsetoperator<<= (unsigned int shift)
 Shift bitset shift bits to the left.  Use the faster bitset::shift_op for constant distance shifts.
bitsetoperator>>= (unsigned int shift)
 Shift bitset shift bits to the right.  Use the faster bitset::shift_op for constant distance shifts.
template<unsigned int shift, class DIRECTION >
void rotate (bitset &result) const
 Rotate bitset.

Detailed Description

template<unsigned int N>
class libecc::bitset< N >

A bitset with a fixed number of bits.

Parameters:
N The number of bits in the bitset.

Constructor & Destructor Documentation

template<unsigned int N>
libecc::bitset< N >::bitset ( void   )  [inline]

Construct an uninitialized bitset of N bits.

Referenced by libecc::operator>>().

template<unsigned int N>
libecc::bitset< N >::bitset ( std::string const &  input  ) 

Construct a bitset of N bits and initialize it with the string input, a hexadecimal value in ASCII representation.

Input is a string of alphanumeric characters ([0-9A-F]) not case sensitive. The input string is read right to left. Any non-space character that is not a hexadecimal digit will terminate reading.

Spaces will be ignored, allowing one to write for example "C20 93B0D12C F78A9001 F6E2841F 0A918FCD" instead of the less readable "C2093B0D12CF78A9001F6E2841F0A918FCD". It is common practise to let each "word" represent an internal digit (32 bits in this example).

If the value passed is larger than fits in the bitset then the most significant bits (the left most characters) are ignored as if the value did fit and then a bit-wise AND was performed with a bitset of N 1's.

Parameters:
input A hexadecimal value in ASCII representation.

References libecc::bitset_base< N >::reset(), and libecc::bitset_base< N >::vector.

template<unsigned int N>
libecc::bitset< N >::bitset ( bitset_digit_t  low_bits  )  [inline, explicit]

Construct a bitset of which only the least significant bits are set.

low_bits must never have more bits set than the size of the bitset N.

References libecc::bitset_base< N >::vector.

template<unsigned int N>
libecc::bitset< N >::bitset ( bitset_digit_t const (&)  v[bitset_base< N >::digits]  )  [inline]

Construct a bitset directly from an array of bitset_digit_t.

The excess bits of the most significant digit (if any) must be zero.

template<unsigned int N>
template<unsigned int m, bool inverted>
libecc::bitset< N >::bitset ( bitset_invertible< m, inverted > const &  bits  )  [inline]

Copy constructor.

The least significant bit (at position 0) of bits and the constructed bitset are lined up. If bits is wider than the constructed bitset then excess bits are lost; if narrower then missing bits are set to inverted. That is, set to zero when bits is not inverted and set to one when bits represents an inverted bitset.

For example, when x is "0000000010001111" (16 bits), y is "10000000" (8 bits), then

 x ^= ~y;

results in x being "1111111111110000".

template<unsigned int N>
template<unsigned int m, bool i1, bool i2, typename OP >
libecc::bitset< N >::bitset ( Operator::bitsetExpression< m, i1, i2, OP > const &  expr  )  [inline]

Construct a bitset from an expression.

See also:
bitset::operator=

Member Function Documentation

template<unsigned int N>
template<typename Expression >
bitset< N > & libecc::bitset< N >::operator&= ( Expression const &  expr  )  [inline]

Assignment operator with bitwise AND.

See also:
bitset::operator=
template<unsigned int N>
bitset& libecc::bitset< N >::operator<<= ( unsigned int  shift  )  [inline]

Shift bitset shift bits to the left.  Use the faster bitset::shift_op for constant distance shifts.

Reimplemented from libecc::bitset_base< N >.

Referenced by libecc::bitset< 512 >::operator<<=().

template<unsigned int N>
template<typename Expression >
bitset< N > & libecc::bitset< N >::operator= ( Expression const &  expr  )  [inline]

Assignment operator.

The least significant bits (at position 0) of expr and this bitset are lined up. If expr is wider than this bitset then excess bits are lost; if narrower then missing bits are set to zero or one depending on whether the expression contains inversion bits.

For example, when x is "0000000010001111" (16 bits), y is "10000000" (8 bits) and z is "11110110" (8 bits), then

 x ^= ~y;

results in x being "1111111111110000". And

 x |= ~y ^ ~z;

results in x being "0000000001110110".

template<unsigned int N>
bitset& libecc::bitset< N >::operator>>= ( unsigned int  shift  )  [inline]

Shift bitset shift bits to the right.  Use the faster bitset::shift_op for constant distance shifts.

Reimplemented from libecc::bitset_base< N >.

Referenced by libecc::bitset< 512 >::operator>>=().

template<unsigned int N>
template<typename Expression >
bitset< N > & libecc::bitset< N >::operator^= ( Expression const &  expr  )  [inline]

Assignment operator with bitwise XOR.

See also:
bitset::operator=
template<unsigned int N>
template<typename Expression >
bitset< N > & libecc::bitset< N >::operator|= ( Expression const &  expr  )  [inline]

Assignment operator with bitwise OR.

See also:
bitset::operator=
template<unsigned int N>
template<unsigned int shift, class DIRECTION >
void libecc::bitset< N >::rotate ( bitset< N > &  result  )  const

Rotate bitset.

Rotate bitset shift bits in DIRECTION.

Parameters:
shift The number of bits to rotate this bitset.
DIRECTION The direction into which this bitset must be rotated, can be libecc::left or libecc::right.
result The result of the rotation.

References libecc::bitset< N >::shift_op().

template<unsigned int N>
template<unsigned int shift, class DIRECTION , class OPERATION >
void libecc::bitset< N >::shift_op ( bitset< N > &  result  )  const

Perform a shift operation followed by a bit operation.

Shift this object shift bits in DIRECTION and then perform operation OPERATION on result with it.

Parameters:
shift the number of bits to shift this object.
DIRECTION can be libecc::left or libecc::right.
OPERATION can be either libecc::assign or libecc::exor.
result The bitset that is used to XOR with, or to assign to.

References libecc::bitset_invertible< N, false >::digit(), and libecc::bitset_base< N >::vector.

Referenced by libecc::bitset< N >::rotate().

Copyright © 2002-2008 Carlo Wood.  All rights reserved.