# convert binary to decimal via stack

hi all,

i am in need of a program, that using a stack, converts a binary number to its decimal one.

can someone pls point me in the right direction?

thank you!
###### Who is Participating?

Where to start Kneidels is using the stack you can use the binary and function for each position:

existing num
&
00000001

Push onto stack

existing num
&
00000010

Push onto stack

What your professor is more than likely looking for is a recursive solution to this problem.  Which you can do the same way you find the prime factorization of a number.  Your recursive function calls use the stack to store data and pop it back off as the recursive function calls are returned.

Hope this gives you a jumping off point with my little hint above.

~Aqua
0

Commented:
Hi kneidels,
> i am in need of a program, that using a stack, converts a binary number
> to its decimal one.

Why does it need to use the stack?

And what exactly do you mean by a binary number?
The source number should be a built-in type like int or long or a string.
Is your source a number formated as a binary number in a string?

David Maisonave (Axter)
Cheers!
0

Author Commented:
Hi David, thanks for the quick reply.

This is actually a homework question (duh!) and i cant figure where to start.

the binary number , like 1001000 (of any length)  - i guess an int.
this must then be translated via a stack  (push, pop) to the decimal equvalent.

in a previous exercize, we had to do it via a recursive function, but i skipped that and i'm starting to regret it :(

thanks again!
0

Commented:
We can't do the homework, but we can help you with exiting code.

Try the implementation, and when you get stuck, post your code with a specific question.

You should first find out what is your source going to be, and what format is the target value going to be.

One or both should be in a string format, otherwise there really isn't anything to convert, since an int can be displayed in both decimal and binary.
0

Author Commented:
thanks , appreciate it.
i'm really lost, but cheers all the same, David.
0

Author Commented:
Thanks Aqua, it sure does give me a starting point
0

*blinks*  Generally when you give a non 'A' grade it is the author's curtosy to give an explination or ask for clarification.  I gave you as much information as I could without you explicitly asking for help on a specific question for a homework assignment.  Might I ask as to why the B grade?

~Aqua
0

Author Commented:
well to honest, i was hoping to get much more help, but i gave you the points anyway, and a candid thank you. and i still appreciate your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.