stacks to convert from decimal to hexadecimal

• 09-25-2004
drdodirty2002
stacks to convert from decimal to hexadecimal
Pardon me chaps, We are using stacks to convert a number, lets say 103, for instance to binary octal and hexadecimal. I am a bit perplexed by the whole situation and I was wondering if you blokes could perhaps share a little bit of your insight with me.I feel as though I've mastered the binary portion of the program.
Code:

``` #include <iostream> #include <iomanip> using namespace std; template <class T, int n> class stack {         private: T elt[n];                         int counter;         public:                 void clearstack() {  counter = -1;                            }                 bool emptystack() {  return counter==-1?true:false;            }         bool fullstack()  {  return counter==n -1?true:false;          }                 void push(T x)    {  counter++; elt[counter]=x;                }                 T pop()          {  T x; x=elt[counter]; counter--;return x;  } }; void main() {  stack <int,7> s;    int m,n,p;  s.clearstack();    cout<<"Enter a number to convert: ";    cin>>m;    while( !  s.fullstack() ) {                   n = m % 2;                           s.push(n);         m =        m / 2; }              while(! s.emptystack())         {         p = s.pop();                        cout<<p;         }         cout<<endl; }```
So if you could help me out with the whole hexadecimal portion of this program I would be very appreciative thank you very kindly.
(english enough for you sean) ;)
• 09-25-2004
sean
Would you please edit your post and start using English in what we like to call, "the right way". I can't even get past your first sentence.
• 09-25-2004
jverkoey
punctuation always helps :D

But I think what you're looking for could be found with a good board search here, or even a....Google search *gasp*
• 09-26-2004
Salem
> void main()
Read the FAQs, watch the Avatar, you know its wrong.

> I feel as though I've mastered the binary portion of the program.
> n = m % 2;
So what's the big jump to %8 for octal and %16 for hex ?