techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old 11-06-2009, 06:41 PM     #1
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Which Algorithm To Use?

Say I have a number that is "x" int long. That I want to divide it by a number that as equally as long.

x == "14"


So what algorithm should I use with C++?


If you need further information, please ask.


Thanks,



Chris
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay

Last edited by Munki; 11-06-2009 at 08:01 PM.
Munki is offline  
Reply With Quote
The Following User Says Thank You to Munki For This Useful Post:
Old 11-06-2009, 06:43 PM     #2
W1zzard
Administrator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

umm .. give an example ?
W1zzard is offline  
Reply With Quote
Old 11-06-2009, 06:44 PM     #3
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

In a C++ Calculator I want to divide 65,000,654,999,000 by 43,998,897,987,888


I wouldnt be asking such a out of the blue question if I wasnt trying to prepare for my next school year. Computer Science requires me to learn to program. Thought I would get a jump on it. Ive tinkered with it before, but nothing as serious as this is going to be.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-06-2009, 06:50 PM     #4
W1zzard
Administrator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

convert to double and divide? or do you need more precision ?

Code:
const char a[]="65000654999000";
const char b[]="43998897987888";

double c=atof(a)/atof(b);
c=1.4773246142867795;

ok that's standard c, not c++, but the basic q is do you want to convert and divide or do you want to divide the "strings" ? in that case a good start would be the same approach how you divide numbers on paper

Last edited by W1zzard; 11-06-2009 at 06:55 PM.
W1zzard is offline  
Reply With Quote
The Following User Says Thank You to W1zzard For This Useful Post:
Old 11-06-2009, 06:58 PM     #5
3870x2
2500 Posts
 
3870x2's Avatar
 
Join Date: Feb 2008
Posts: 2,739 (4.31/day)
Thanks: 50
Thanked 295 Times in 261 Posts

System Specs

wow w1zz, you are very hardcore. I dont even have a C compiler on this machine! pretty much nothing before 1973 on here :P
__________________
A+, N+, S+, MCSE.
Heatware my FS thread
STEAM ID Name: furi0nst0rmrage (0s are zeros)
3870x2 is offline  
Reply With Quote
Old 11-06-2009, 07:57 PM     #6
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by W1zzard View Post
convert to double and divide? or do you need more precision ?

Code:
const char a[]="65000654999000";
const char b[]="43998897987888";

double c=atof(a)/atof(b);
c=1.4773246142867795;

ok that's standard c, not c++, but the basic q is do you want to convert and divide or do you want to divide the "strings" ? in that case a good start would be the same approach how you divide numbers on paper

Well obviously im a n00b, because I used single quote for a int where I needed to use a double quote in my OP. I noticed you turned my numbers into ASCII then, ASCII into Float, im still trying to process how the computer will see it. Like what "65000654999000" would look in ASCII.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-06-2009, 08:05 PM     #7
W1zzard
Administrator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

"65000654999000" looks like "65000654999000" .. thats what a string is .. when you put it into "

single quote defines a single character: char ch='x';

other in-memory representations, educational, you will probably never need to know why it looks like that

float a=65000654999000;


double a=65000654999000;


uint64 a=65000654999000;
W1zzard is offline  
Reply With Quote
Old 11-06-2009, 08:07 PM     #8
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by W1zzard View Post
"65000654999000" looks like "65000654999000" .. thats what a string is .. when you put it into "

other in-memory representations, educational, you will probably never need to know why it looks like that

double a=65000654999000;
http://img.techpowerup.org/091106/Capture221.jpg

uint64 a=65000654999000;
http://img.techpowerup.org/091106/Capture222.jpg


Okay when in integer form its just the number, period. How would I go about changing char ' 65000654999000' ?
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-06-2009, 08:08 PM     #9
W1zzard
Administrator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 7,628 (3.78/day)
Thanks: 79
Thanked 2,498 Times in 938 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

you can not create a single ascii character that contains 65000654999000 .. a single character is just a single character, not several characters
W1zzard is offline  
Reply With Quote
Old 11-06-2009, 08:10 PM     #10
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by W1zzard View Post
you can not create a single ascii character that contains 65000654999000 .. a single character is just a single character, not several characters

I understand, but could you create an array of char to form said num?
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-06-2009, 08:12 PM     #11
Kreij
TPU Hit Squad Member
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts

System Specs

He did that in post #4 using

const char[] a = "123456789"

The brackets mean the variale or constant (in this case 'a') is an array.
__________________
53452340602F55453253602E35572D$20
Kreij is offline  
Reply With Quote
Old 11-06-2009, 08:16 PM     #12
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by Kreij View Post
He did that in post #4 using

const char[] a = "123456789"

The brackets means it is an array.


ASCII is a set chart of conversions? Im a complete n00b here, but im going to have to bite the bullet and try to learn even if im asking questions that have no meaning. I wanted to make a C++ calculator that did 14 digit numbers.


So when he did Const Char a[] = " 12345678 "

Char is referring to ASCII. ASCII does not contain such a number.


65000654999000 is a 6 byte number.

and W1zzard used a double which can handle up to 8 Bytes correct?

and the



double c=atof(a)/atof(b);

double c == answer?

atof == ASCII to Float

So in this case the ASCII code is 'a' for "65000654999000"
and 'b' is for "43998897987888"

and the \ is telling it to divide Array 'a' by array 'b'?


Can someone verify this for me?
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay

Last edited by Munki; 11-06-2009 at 08:48 PM.
Munki is offline  
Reply With Quote
Old 11-06-2009, 08:51 PM     #13
Kreij
TPU Hit Squad Member
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts

System Specs

When you enclose something in double quotes (like "1234") it takes it as a string literal, not the value of the numbers. So so the computer sees "1234" as ascii 49,50,51 & 51.

When you send a string into a character array it simply breaks the string into it's respective characters.

char[] A = "1234"

So A[0] will be equal to ascii 49 and visually represented as the number 1
A[1] will be ascii 50 etc. etc.

In order to do mathematical calculations on the string literal you have to cast it back to a number.

That is what atof(string) did. atof means ascii to floating point number.
__________________
53452340602F55453253602E35572D$20
Kreij is offline  
Reply With Quote
Old 11-06-2009, 08:56 PM     #14
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by Kreij View Post
When you enclose something in double quotes (like "1234") it takes it as a string literal, not the value of the numbers. So so the computer sees "1234" as ascii 49,50,51 & 51.

When you send a string into a character array it simply breaks the string into it's respective characters.

char[] A = "1234"

So A[0] will be equal to ascii 49 and visually represented as the number 1
A[1] will be ascii 50 etc. etc.
Im slowly understanding this, im sure its taking my longer than it would take a mentally ill patient, but its going. So what your telling me is that when I call Char its going to break "1234" into "1" "2" "3" "4" *ASCII* and if I just call Int "1234" It sees it as one number?


Example for verification:


Const Char A[] -= "1234"


Char A[0] = 1 *ASCII*
Char A[1] = 2
Char A[2] = 3
Char A[3] = 4



Back on in about 30 mins.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-06-2009, 09:01 PM     #15
Kreij
TPU Hit Squad Member
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts

System Specs

Quote:
Originally Posted by Munki View Post
Im slowly understanding this, im sure its taking my longer than it would take a mentally ill patient, but its going. So what your telling me is that when I call Char its going to break "1234" into "1" "2" "3" "4" *ASCII* and if I just call Int "1234" It sees it as one number?


Example for verification:


Const Char A[] -= "1234"


Char A[0] = 1 *ASCII*
Char A[1] = 2
Char A[2] = 3
Char A[3] = 4



Back on in about 30 mins.
Remember that A[0] is NOT the ascii code 1 (which would be SOH "Start Of Heading"), but the ascii character '1' (which has an ascii code of 49)
__________________
53452340602F55453253602E35572D$20
Kreij is offline  
Reply With Quote
Old 11-07-2009, 06:36 AM     #16
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by Kreij View Post
Remember that A[0] is NOT the ascii code 1 (which would be SOH "Start Of Heading"), but the ascii character '1' (which has an ascii code of 49)
So, don't use char A[0]

?
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-07-2009, 07:00 AM     #17
Kreij
TPU Hit Squad Member
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts

System Specs

No. When you doing calculations you will have to do them in a type that is numerical (int, float, double). When you are doing input and output you will need to display them in a string or character format. You will simply have to convert between them to accomplish what you want.

So for instance let say you ask the user for two numbers. They type in 10 and 20 on the keyboard. This will be in string format "10" and "20"

Convert them to numeric format.
Int a = atoi("10")
Int b = atoi("20")

Add them together...
Int c = a + b

output the result

char[] output = itoa(c)

You must learn the basic types of the language and how they are used and converted.
It's not hard, it will just take some studying.

As always, we are here to help.
__________________
53452340602F55453253602E35572D$20
Kreij is offline  
Reply With Quote
Old 11-07-2009, 01:05 PM     #18
Oliver_FF
250 Posts
 
Oliver_FF's Avatar
 
Join Date: Oct 2006
Posts: 459 (0.40/day)
Thanks: 23
Thanked 55 Times in 47 Posts

System Specs

For anyone interested in doing really really really big arithmetic...

There is a library out there called "The GNU Multiple Precision Arithmetic Library" which lets you perform arithmetic on arbitrary length numbers

You can do cool stuff like:
Code:
mpz_t n;
mpz_init_set_str (n, "184764827574746458753962934628956823764982346829348264826583465893465389465262894689326583946589346583465834", 10);

mpz_t pie;
mpz_init_set_str (pie, "3141592653589793238462643383279502884", 10)

// n = n - pie;
mpz_sub (n, n, pie);
Oliver_FF is offline  
Reply With Quote
Old 11-07-2009, 01:14 PM     #19
TheMailMan78
2500 Posts
 
TheMailMan78's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 4,594 (5.08/day)
Thanks: 324
Thanked 871 Times in 560 Posts

System Specs

WOW! There is so much math in this thread it makes my butthole pucker!
__________________
A monster lies in wait for me.
A stew of pain and misery,
But fiercer still in life and limb.
Is me that lies in wait for him.
Rate TheMailBox
TheMailMan78 is offline  
Reply With Quote
Old 11-08-2009, 07:39 AM     #20
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Well I am trying, last night I didnt come back to TPU because I had my head in a C++ book that deprived me of $35 Sure hope it pays off....im working on a calculator that uses this as I type this.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-08-2009, 08:50 AM     #21
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Okay well, im about to install my compiler and see how well my first program works. Wish me luck, God knows im going to need it.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-08-2009, 10:39 AM     #22
<<Onafets>>
500 Posts
 
<<Onafets>>'s Avatar
 
Join Date: Nov 2008
Location: Sydney, Australia
Posts: 553 (1.45/day)
Thanks: 311
Thanked 65 Times in 64 Posts
Send a message via MSN to <<Onafets>>

System Specs

Good luck..wanna learn C++ too so I can make some hardcore programms and send viruses to those bitches in year 6. 3 More years to year 10, 3 More years to year 10, 3 More years to year 10...
__________________


“Why would you do that, o i have a question can you uninstall and install any graphics card while the OS is runing and your rig is runing, i just always shit it down before i add, change, or move a video card in the x16 slots.” -3volvedcombat
<<Onafets>> is offline  
Reply With Quote
Old 11-08-2009, 11:52 AM     #23
Munki
250 Posts
 
Munki's Avatar
 
Join Date: Sep 2008
Location: Georgia
Posts: 300 (0.69/day)
Thanks: 21
Thanked 23 Times in 20 Posts
Send a message via AIM to Munki

System Specs

Quote:
Originally Posted by <<Onafets>> View Post
Good luck..wanna learn C++ too so I can make some hardcore programms and send viruses to those bitches in year 6. 3 More years to year 10, 3 More years to year 10, 3 More years to year 10...
What in the hell are you talking about?



BTW the program worked Just a bit messy. Gotta do some cleanup.
__________________


Referances:
Heatware: ipphreak
ebay: mollymay506
amazon: insane_monkay
Munki is offline  
Reply With Quote
Old 11-08-2009, 01:37 PM     #24
TheMailMan78
2500 Posts
 
TheMailMan78's Avatar
 
Join Date: Jun 2007
Location: Miami, FL
Posts: 4,594 (5.08/day)
Thanks: 324
Thanked 871 Times in 560 Posts

System Specs

Quote:
Originally Posted by Munki View Post
Well I am trying, last night I didnt come back to TPU because I had my head in a C++ book that deprived me of $35 Sure hope it pays off....im working on a calculator that uses this as I type this.
I guess you are doing better than I ever will. If someone had my children for ransom and asked me to solve any of those things yall were talking about I would have no idea where to start. However Ill paint the hell out of a landscape.
__________________
A monster lies in wait for me.
A stew of pain and misery,
But fiercer still in life and limb.
Is me that lies in wait for him.
Rate TheMailBox
TheMailMan78 is offline  
Reply With Quote
Old 11-08-2009, 02:34 PM     #25
Kreij
TPU Hit Squad Member
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 3,242 (3.18/day)
Thanks: 92
Thanked 767 Times in 582 Posts

System Specs

Having a book for reference will come in handy, Munki. It's easier that always having to search through the net for answers for basics.

As soon as you get some code going, post it here so we can take a look at it and help you out.

PS. I have no idea what Onafets is talkiing about either. lol
__________________
53452340602F55453253602E35572D$20
Kreij is offline  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which audio to use theonetruewill General Hardware 6 07-10-2007 11:54 PM
Which program to use trt740 Overclocking & Cooling 4 05-29-2007 08:56 PM
Which to use gerrynicol Graphics Cards 20 08-29-2006 08:32 PM
Which should i use? BigD6997 Graphics Cards 5 07-06-2006 12:48 AM


All times are GMT. The time now is 03:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
no new posts