Thread: stacks to convert from decimal to hexadecimal

  1. #1
    Registered User
    Join Date
    Apr 2003

    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.
    #include <iostream>
    #include <iomanip>
    using namespace std;
    template <class T, int n>
    class stack
    	private: T elt[n];
    			 int counter;
    		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;
     cout<<"Enter a number to convert: ";
     while( !  s.fullstack() )
    	 n = m % 2;
    	 m =	m / 2;
        while(! s.emptystack())
    	 p = s.pop();	
    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)
    Last edited by drdodirty2002; 09-25-2004 at 09:16 PM.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    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.

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    punctuation always helps

    But I think what you're looking for could be found with a good board search here, or even a....Google search *gasp*
    Last edited by jverkoey; 09-25-2004 at 09:08 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > 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 ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert from Single to Decimal
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-11-2008, 06:13 AM
  2. Convert DegMinSec to Decimal Degrees
    By JacquesLeJock in forum C Programming
    Replies: 3
    Last Post: 11-21-2007, 11:59 PM
  3. how to convert decimal to hexa decimal in C/
    By kalamram in forum C Programming
    Replies: 4
    Last Post: 09-03-2007, 07:39 AM
  4. Replies: 10
    Last Post: 08-17-2005, 11:17 PM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM