how can I program a caltulator which does process between 2,3,4,5,6,7,8,9,10 based numbers.
for example asuume that these are two based numbers (111)+(101)=1000
I want to build a program which can do these procces.Please help me.
This is a discussion on calculator within the C++ Programming forums, part of the General Programming Boards category; how can I program a caltulator which does process between 2,3,4,5,6,7,8,9,10 based numbers. for example asuume that these are two ...
how can I program a caltulator which does process between 2,3,4,5,6,7,8,9,10 based numbers.
for example asuume that these are two based numbers (111)+(101)=1000
I want to build a program which can do these procces.Please help me.
first make a function that can convert a base 10 number to a base 2, 3, 4, 5 etc.
and vice versa
too late to remember the method ;0
so basically you do the math w/ base 10
so
111 (base2) + 101 (base2) is really
7 + 5
so a computer can understand that
do the math
convert back to base2
Making the function is the hard part. I forgot how to convert from anything other than base 2 and 8 =/
You are asking about the algorithm or about the coding, I mean do you know how to convert between bases or you not?
What exactly do you need to know.
both algoritihm and coding
ok i can give you algorithy for base 10 to base 2
take a base 10 number ie 15
module (% operator) by 2
that is your remainer, which is the least significant digit of the base 2 number
then divide by 2, which gives you 7 (least it should w/ int)
module again by 2
that remainer is your next least sig. digit
divide by 2
repeate till your division = 0
*edit*
click on the 'edit' button to visualize how things should line up properly
*edit*
*edit*
mebe this helps
*edit*
3 edits' later, i give up
*edit*
so for 15:
15%2 =_____1__| least sig. digit
15/2 = 7 _______|
7%2 = _____ 1__|
7/2 = 3 ________|
3%2 = _____1__|
3/2 = 1 ________|
1%2 = _____1__| most sig. digit
1/2 = 0 end_____V
=============
1111 = 15 (base 2)
btw, search this stuff on the web, i'm sure they're a zillion resources. Keyword = converting base or converting base 10, 2
Last edited by Diamonds; 10-31-2002 at 06:31 AM.
If you don't know how to do it mathimaticaly, my advice to you is to learn that first then try to write the code.
the example of converting from base 10 to base 2, will work on all conversion operations from a base to a smaller base.
Try searching the web or writting the code for the base 10 to 2 converter and see what you will get.
oh yeah haha, forgotOriginally posted by ammar
the example of converting from base 10 to base 2, will work on all conversion operations from a base to a smaller base.
Here's a function that converts a number of any base (1-36) in string form to an integer.
Code://String to integer int P__StrToNum(const char* str, int base) { unsigned int digit, number = 0; while (*str) { if (isdigit(*str)) digit = *str - '0'; else if (islower(*str)) digit = *str - 'a' + 10; else digit = *str - 'A' + 10; number = number * base + digit; str++; } return(number); }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
This I found on this site a while ago............
Should help
Such is life.
Oh, and this.......
Not my work, but look and you will find..
Such is life.
thank you very much.
but my problem is a little more complicated look at this;
111+101=1000 in a 2 based additon process.
how can I make a calculator which does a process like this.
I want a calculator which makes 4 process between based numbers.
after the numbers (111, 102, etc..) are inputted and stored in an integer variable, just convert them to base 10 then do the calculation then convert then back to base 2 so its outputted the way you inputted them...
did you get all that?
Please direct all complaints regarding this post to the nearest brick wall Have a nice day.
Dont think it was understood .
But all the answers are in my two attachments. Use Baseconv.zip to change to base 10 (if you must), do the calculation, and change back- Then use the code in calc program.
Sorted
Such is life.