#include <iostream>
#include <climits>
 
void int2bin(int x,int d);
void printNum(int x, int d);
 
using namespace std;
 
int main() {
 
	int iNumber1 = 18;
	int iNumber2 = 63;
	int iPlaces = 8;
 
	cout << "First number:" << endl;
	printNum(iNumber1,iPlaces);
	cout << endl <<"Second number:" << endl;
	printNum(iNumber2,iPlaces);
	cout << endl <<"Binary not for first number:" << endl;	
	printNum(~iNumber1,iPlaces);
	cout << endl <<"Binary or:" << endl;
	printNum(iNumber1 | iNumber2,iPlaces);
	cout << endl <<"Binary and:" << endl;
	printNum(iNumber1 & iNumber2,iPlaces);
	cout << endl <<"Binary xor:" << endl;
	printNum(iNumber1 ^ iNumber2,iPlaces);
	cout << endl <<"Binary bitshift left for first number:" << endl;	
	printNum(iNumber1 << 1,iPlaces);
	cout << endl <<"Binary bitshift right for first number:" << endl;	
	printNum(iNumber1 >> 1,iPlaces);
 
	cout << endl <<"INT_MIN: " << INT_MIN << endl;	
	cout << "INT_MAX: " << INT_MAX << endl;	
 
	// Generates integer overflow warning during compile
	cout << "INT_MIN - 1: " << INT_MIN - 1 << endl;	
	cout << "INT_MAX + 1: " << INT_MAX + 1 << endl;
 
	return 0;
}
 
void printNum(int x, int d) {
	cout << "Normal: " << x << endl << "Binary: ";
	int2bin(x,d);
}
 
void int2bin(int x,int d){
      char buffer[33];
      int index=0;
      for (;d>0;d--){
        buffer[index++] = '0'+ (x & 1);
            x >>= 1;
      }
    while (index >0 ) printf("%c",buffer[--index]);
}