?
Solved

convert binary to decimal via stack

Posted on 2006-05-09
8
Medium Priority
?
624 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:kneidels
  • 4
  • 2
  • 2
8 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 16642303
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 Comment

by:kneidels
ID: 16642621
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
 
LVL 30

Expert Comment

by:Axter
ID: 16642748
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:kneidels
ID: 16643297
thanks , appreciate it.
i'm really lost, but cheers all the same, David.
0
 
LVL 10

Accepted Solution

by:
Andrew Beers earned 375 total points
ID: 16643473
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
 

Author Comment

by:kneidels
ID: 16643661
Thanks Aqua, it sure does give me a starting point
0
 
LVL 10

Expert Comment

by:Andrew Beers
ID: 16644617
*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 Comment

by:kneidels
ID: 16650299
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question