#include
#include
// using these directives spares me of h
// aving to type the
// namespace qualifier std:: in front ea
// ch one everytime
// I use it
using std::cout;
using std::endl;
using std::bitset;
int main ()
{
// create a couple of arbitrary long integers
unsigned long testA = 34233;
unsigned long testB = 332311;
// here we use the bitset template class I'll break it down
// bitset : name of the template class as defined in the
// <32> : the number of bits we are interested in, a long is garaunteed
// to be at least this many bits, we can use less than 32, but
// more could potentially be non-portable
// resultA : the name of the variable
// (testA) : the value we initialize the variable, we could of put the
// number itself in or even left it blank which would yield
// a bitset of 32 0-bits
bitset<32> resultA(testA);
bitset<32> resultB(testB);
// here we output the bitset testA
cout << "testA (" << testA << "): " << endl;
for(int i = 0; i < 32; ++i)
{
cout << resultA[i];
}
cout << endl << endl;
// output the bitset testB
cout << "testB (" << testB << "): " << endl;
for(int j = 0; j < 32; ++j)
{
cout << resultB[j];
}
cout << endl << endl;
return 0;
}