#include<iostream>
using namespace std;

class binaerzahl {
   int bits[64];

public:
     // Konstruktor
     binaerzahl () {
        for (int i = 0; i <= 63; i++)
           bits[i] = 0;
     }

     // Methode set_bit
     bool set_bit (int pos) {
        if ((pos < 0) || (pos > 63))   // Bereichsueberschreitung pruefen
           return false;               // uebergebene Position ist ungueltig 
      
        bits[pos] = 1;                 // Bit an gueltiger Position setzen
        return true;
     }

     // Methode increment
     void increment () {
        for (int i=0; i <= 63; i++) {   // Pruefen der einzelnen Bits
            if (bits[i] == 0) {        // erstes 0-Bit gefunden
               bits[i] = 1;            // Bit auf den Wert 1 setzen
               return;                 // Methode beenden
            }
            else  
               bits[i] = 0;            // Alle 1-Bits bis zum 1. 0-Bit
        }                              // auf 0 setzen 

     }
     
     // Methode output
     void output () {
        for (int i = 63; i >= 0; i--)
           cout << bits[i];
     }



};

int main () {
   binaerzahl bzahl;

   cout << "\n1. Test - Initialisierung" << endl;
   cout << "=========================" << endl;
   cout << "Binaerzahl: " ;
   bzahl.output(); 
   cout << endl << endl;

   cout << "2. Test - Methode set_bit" << endl;
   cout << "=========================" << endl;
   cout << "Bereichsüberschreitung bei Index -2 : ";
   if (bzahl.set_bit(-2)) 
      cout << "wurde nicht erkannt" << endl;
   else
      cout << "wurde erkannt" << endl;

   cout << "Bereichsüberschreitung bei Index 100 : ";
   if (bzahl.set_bit(-100)) 
      cout << "wurde nicht erkannt" << endl;
   else
      cout << "wurde erkannt" << endl;

   cout << "Binaerzahl nach dem Test: " ;
   bzahl.output(); 
   cout << endl << endl;
   
   cout << "Setzen der Bits 2 bis 20 und 61 und 62" << endl;
   for (int i=2; i <= 20; i++)
      if (!bzahl.set_bit(i))
         cout << "set_bit liefert false für index " << i << endl;

   bzahl.set_bit(61);
   bzahl.set_bit(62);
   
   cout << "Binaerzahl nach dem Test: " ;
   bzahl.output(); 
   cout << endl << endl;

   cout << "3. Test - Methode increment" << endl;
   cout << "===========================" << endl;
   cout << "       1. Aufruf : ";
   bzahl.increment();
   bzahl.output(); 
   cout << endl << endl;

   cout << "       2. Aufruf : ";
   bzahl.increment();
   bzahl.output(); 
   cout << endl << endl;

   cout << "       3. Aufruf : ";
   bzahl.increment();
   bzahl.output(); 
   cout << endl << endl;

   cout << "      50. Aufruf : ";
   for (int i=4; i <= 50; i++)
       bzahl.increment();

   bzahl.output(); 
   cout << endl << endl;

    cout << "11050000. Aufruf : ";
   for (int i=51; i <= 11050000; i++)
       bzahl.increment();

   bzahl.output(); 
   cout << endl << endl;
}

