Hi there ..
i need a source code for a program written in C++ to convert a number in base b to a number in base c, while both b and c can be equal to either 2, 8, 10, or 16.
i'll really appreciate it if anyone can help
& thanX
Hi there ..
i need a source code for a program written in C++ to convert a number in base b to a number in base c, while both b and c can be equal to either 2, 8, 10, or 16.
i'll really appreciate it if anyone can help
& thanX
itoa(i,buffer,base)
To be or not to be == true
Here i have attached the complete code for the same..EnjoyOriginally Posted by Nora
Last edited by Salem; 12-09-2006 at 07:45 AM. Reason: Remove attachment
If the OP has not attmpted to solve the problem, please do not write the entire codeHere i have attached the complete code for the same..Enjoy
for them. It really does go against the learning process
I'm just trying to be a better person - My Name Is Earl
Oh, i am sorry if it was against the rules. Mods can delete it.....Sorry againOriginally Posted by swgh
itoa (ugh), strtol or *scanf or *printf (old), or stringstreams would work. Even regular old math would work.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Hi again..
i'm just a begginer in C++ .. and i have the problem i mentioned before as a project..
i've tryed to solve it .. and i have some questions..
is it right if do the following:
cout>>"Please enter the number you want to convert followed by its base";
cin<<num,base;
then i put an "if"statement .. if the base is not equal to 10 then it will enter a "for" loop to convert it it to a decimal number..then another loop to convert this decimal to the base that the user choose after that..
this is for a start is it right or i have to think about something else? cuz i need to know so that i can go on with the rest of the code..
that's it.. thank you all for ur replys
Well you start with a very simple program which
- prompts for input (you've had a go at that)
- reads input (you've had a go at that as well)
- prints what was input.
When that's working, move onto the next small step of the program, or if you're still stuck, post the code you have so far.
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.
Hi all ...
i getting really tired by this source code! i have asked our TA about it.. and he said u need to use strings in order to make it easier for you .. but we didn't learn strings at all!
so its becaming really complicated :s i got the source where i convert from decimal to any base .. i just need the source that convert from any base to decimal... any help from anyone would be really helpful cuz i'm really desperate :/
Originally Posted by NoraCode:Base 2(binary) -> Base 10(decimal) 100101 -> 1*2^0 + 0*2^1 + 1*2^2 + 0*2^3 + 0*2^4 + 1*2^5 = 1 + 0 + 4 + 0 + 0 + 32 = 37 Base 8(oct) -> Base 10(decimal) 720123 -> 3*8^0 + 2*8^1 + 1*8^2 + 0*8^3 + 2*8^4 + 7*8^5 = 237 651 Generally. By converting from base X to base 10, you have to use this technique Let's say A is an array (0-based index - meaning that the array's indexes are 0 1 2 3 ...) A = { 1, 0, 1, 0, 0, 1 } //The numbers from the 1st example - except they are written backwards, so as not to mess up those indexes. You have to read the indexes from right to left and then number them 0 1 2 3 and so on, but in C and C++, arrays start with index 0, thus if you would write the numbers in the same order that you see them in the 1st example, the indexes would be reversed. then you have to add them together using this formula: A[i]*X^i + A[i + 1]*X^(i + 1) .. A[the number of elements in the array A - 1]*X^(the number of elements in the array A - 1) If you still don't get it, use Google!