How do you implement a binary number to convert into an equivalent decimal number using stack in C++.I am having a headache here.I have been thinking the past 2 days but without much knowledge in C++ i am partially dead. Tried reading books but still can't figure it out and time is running short on me.Please advice and help.Thanks in advance
Kellaw 0 Newbie Poster
Recommended Answers
Jump to PostThere are essentially two steps to the problem, given
void foo ( int num );1. do something with num % 2
2. call foo ( num / 2 );Changing the order of those two steps changes what happens - feel free to experiment.
Oh, and …
Jump to PostYou might want to wack that in a header file or something.
Next step would be to test your stack implentation using a main().
Try simple stuff like pushing a bunch of numbers onto the stack then systematically popping them out, whilst at the same time displaying them …
Jump to Post>No offense man, but that is technically doing it most of the work for him..how can he learn then?
That's nice, but if you read before most of that code was written by him, I just showed him how to use it with chars.
>Do leave me with …
Jump to Post>for (i=0;i<15;i++)
stack.push(x/(power(10,i))%10)I honestly have no idea why you would want to do it that way instead of using chars? Obviously, I've never worked with peripheral devices like bar scanners so I don't know how the information is coming in.
It seems odd though, that you insist …
Jump to Posthey all
first i am web developer not software one, but i had knowledge in algorothem.
kellaw i won't write code only i will tell u the algorithgm.
i suppose the binary stack is stored in array (A) from left to right.
first create 2 arrays (B) and (C) with …
All 44 Replies
Kellaw 0 Newbie Poster
Salem 5,265 Posting Sage

iamthwee
Kellaw 0 Newbie Poster

iamthwee
Kellaw 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
Kellaw 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
Kellaw 0 Newbie Poster

iamthwee
dreamreaver 0 Newbie Poster

iamthwee
Kellaw 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
Kellaw 0 Newbie Poster

iamthwee
Kellaw 0 Newbie Poster

iamthwee
Kellaw 0 Newbie Poster
Kellaw 0 Newbie Poster

iamthwee

iamthwee
Kellaw 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
Lerner 582 Nearly a Posting Maven
Kellaw 0 Newbie Poster
Kellaw 0 Newbie Poster

iamthwee
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.