Bitwise Operators

sint2t is signed_int< 64 > on most 32 bit machines.

Contents

Not (~)

sint2t a, b;

for ( unsigned i = 0; i < (2 * UINT_BITS); ++i )
{
  set_bit( a, i, i & 1 );
  set_bit( b, i, ~i & 1 );
}

CHECK( (~a) == b );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

Ok

And (&)

sint2t a, b;

for ( unsigned i = 0; i < (2 * UINT_BITS); ++i )
{
  set_bit( a, i, i & 1 );
  set_bit( b, i, ~i & 1 );
}

CHECK( (a & b) == 0 );

a <<= 1;

CHECK( (a & b) == a );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

Ok

Or (|)

sint2t a, b;

for ( unsigned i = 0; i < (2 * UINT_BITS); ++i )
{
  set_bit( a, i, i & 1 );
  set_bit( b, i, ~i & 1 );
}

CHECK( (a | b) == -1 );

a <<= 1;

CHECK( (a | b) == b );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

Ok

Xor (^)

sint2t a, b;

for ( unsigned i = 0; i < (2 * UINT_BITS); ++i )
{
  set_bit( a, i, i & 1 );
  set_bit( b, i, ~i & 1 );
}

CHECK( (a ^ b) == -1 );

a <<= 1;

CHECK( (a ^ b) == 1 );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

Ok