#include<iostream>
usingnamespace std;
class stack
{
private:
int a[8];
int counter;
public: void clearStack() {counter = 0;}
bool emptyStack() { if (counter == 0) returntrue; elsereturnfalse; }
bool fullStack() { if (counter == 8) returntrue; elsereturnfalse; }
void pushStack(int x) { a[counter] = x; counter++; }
int popStack() { counter--; return a[counter]; }
};
int main()
{
int n;
stack s;
s.clearStack();
cout << "Enter a positive number: ";
cin >> n;
cout << n <<" at base 2 is: ";
while (n != 0)
{
int r;
r = n % 2; s.pushStack(r);
n = n / 2;
}
while (!s.emptyStack())
{
int x = s.popStack();
cout << x;
}
cout << endl;
s.clearStack();
cout << n << " at base 8 is: ";
while (n != 0)
{
int r;
r = n % 8; s.pushStack(r);
n = n / 8;
}
while (!s.emptyStack())
{
int x = s.popStack();
cout << x;
}
cout << endl;
s.clearStack();
cout << n << " at base 16 is: ";
while (n != 0 )
{
int r;
r = n % 16; s.pushStack(r);
n = n / 16;
}
while (!s.emptyStack())
{
int x = s.popStack();
cout << x;
}
}
/*
Enter a positive number: 163
163 at base 2 is: 10100011
0 at base 8 is:
0 at base 16 is: Press any key to continue . . .
*/