|
Hi everybody, i am writing some functions for arithmetic operations with Huge numbers(more than 1000 digit), i am using CString class and i treat CString objects like numbers,for example :
CString s1,s2,s3;
s1="625";
s2="25";
s3=Divide(s1,s2); // now s3="25"
I have to convert Huge numbers to binary, so using simple algorithm(dividing by 2,...) is too slow, so i decided to convert these numbers first to Hex then from Hex to binary,(as converting to Hex to Bin is very fast as you know)
i thought it would make my func faster but it takes approximately the same time ?? Does anybody know why ?? or have any ideas??
Regards
m0n0
m0n0
|
|
|
|
|
Are you saying that you're using your own custom functions that perform mathematical functions on numerical strings that can run to a 1000 digits?
I Dream of Absolute Zero
|
|
|
|
|
|
Yes,not only 1000 digit but much more . How many symbols CString objects can contain ,thats INT_MAX=2147483647;
m0n0
|
|
|
|
|
Yes. I did this type of project for fun about 14 years ago. It supported the four basic operators plus factorial and exponents. I'm not sure why he is going to all of the trouble of converting from one base to another though. I'm unsure of its necessity.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I need to test these huge numbers on primality using probabilistic tests,and that's where i need converting to binary, because how do u suggest calculating for example this :
3535783465873657834623842893472389475 ^ 234623784627834682374823476782346823746823 mod (128) = ?
^ is Power
and when i convert this number to binary then there is a algorithm which calculates this number x^y (mod n) very easily and fastly.
I think it's clear to u now David why i need convertion to binary
m0n0
|
|
|
|
|
Giorgi Moniava wrote:
I think it's clear to u now David why i need convertion to binary
Not yet. The exponent and modulo operator can be implemented without using base-2.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Yes but how do you think how long will it take my program to calculate smth. like this
2346235345345345345347846823746236454 ^ 237436452376234234234234234545465 , using standard exponent algorithm , for example 5^3 = 5*5*5 = 125 , processor will have to multiply this number : 2346235345345345345347846823746236454 on itself ,
237436452376234234234234234545465 times .Thats pretty long process
m0n0
|
|
|
|
|
Well, even if you converted such a long number to binary, you've got no std function to do std operations like ^ or mod. Processors usually take 32 or 64 bit numbers. For better performance try search the web for additional libs for processing huge numbers. I'm sure there are some. Maybe even with some source...
|
|
|
|
|
Hey Everybody!
I want to use shellexecute for files in the same directory as my application,
but using shellexecute I have to use the absolute path and not the relative path (which is the app's directory).
is there any command to run a program using relative path? and if not, how can I find the app's path, so I can use it as a variable in the shellexecute?
Thanks everybody!!!
|
|
|
|
|
here is small MFC based example
{
CString szCurrentDirectory;
CString csPath;
::GetModuleFileName(NULL,szCurrentDirectory.GetBuffer(MAX_PATH),MAX_PATH);
szCurrentDirectory.ReleaseBuffer();
csPath=szCurrentDirectory.Left(szCurrentDirectory.ReverseFind('\\')));
#ifdef _DEBUG
OutputDebugString(csPath);
#endif
}
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Hey! thanks!
works great, but I'm trying to understand the whole code and
there are some things I don't quite understand (I'm pretty much a beginner in this whole thing).
I hope you don't mind giving me a short explaination...
::GetModuleFileName(NULL,szCurrentDirectory.GetBuffer(MAX_PATH),MAX_PATH);
okay, I understood that it returns the whole path including the file name (which of that you got rid later), but I didn't really understand what GetBuffer does. does it get the LPTSTR from the szCurrentDirectory CString???
I'm really confuzed here...
szCurrentDirectory.ReleaseBuffer();
I did understand that you need to release the buffer in order to get rid of the filename and get only the whole path.
csPath=szCurrentDirectory.Left(szCurrentDirectory.ReverseFind('\\'));
and what does szCurrentDirectory.Left do?
or the ReverseFind? I understood that it "erases" the filename, but I don't really get what each function is doing...
Thanks ALOT!!!
|
|
|
|
|
Green Fuze wrote:
does it get the LPTSTR from the szCurrentDirectory CString???
Yes, I allocate the temporary LPSTR buffer of SIZE MAX_PATH from CString
Green Fuze wrote:
szCurrentDirectory.ReleaseBuffer();
Actually using this we instruct the CString variable to take control of temporary BUFFER
Green Fuze wrote:
I did understand that you need to release the buffer in order to get rid of the filename and get only the whole path.
Nope, I will do that in next step!
Green Fuze wrote:
szCurrentDirectory.Left do?
Its copy n character from left of string i.e. let you string="codeproject" ; and i ask for string.left(4); then this string return me "code"
Green Fuze wrote:
ReverseFind
actually I try to find last '\' in the string as you already knows that filename with directory is something like this c:\codeproject\cp\filename.exe so, using ReverseFind function I find the last '\' and it return me exact location of that '\' and using CString::Left I copy required string into new variable.
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Thanks!!!
you're a real savior!
I really like that Left thing, nice thinking!
but I'm using the "_splitpath()" command, instead of Left (as DavidCrow suggessted, just looks better for the job, but I still learnt something important!)
thanks!
|
|
|
|
|
|
ThatsAlok wrote:
csPath=szCurrentDirectory.Left(szCurrentDirectory.ReverseFind('\\')));
It's much more reliable to use _splitpath() than ReverseFind() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hey, thanks!
works great!!!
|
|
|
|
|
hi all
I have problem with the retrieving the file names from the specific folder.I am having .dll files in the folder and i wan the names of the files one by one .it's urgent .In mfc .
waiting for the reply
Best regards
Ganesh Takawle
|
|
|
|
|
|
void Find(CString dir_path)
{
CFileFind f;
CString path = dir_path;
CString LISTOFFILES;
if(path.Right(1) != "\\")
path += "\\";
path += "*.*";
bool res = f.FindFile(path);
while(res)
{
res = f.FindNextFile();
if (!f.IsDots()&&!f.IsDirectory())
LISTOFFILES+=f.GetFilePath()+"\n";
}
}
LISTOFFILES now contains all names of files which are in the dir_path directory(not including subfolders)
Example : Find("c:\\downloads\\")
|
|
|
|
|
hi
Thanx for the solution .
It worked really fine and want it the same way..
Best Regards
Ganesh
|
|
|
|
|
Hello there,
Is it possible to define the time a CAsyncSocket object will hang in a Connect call before it fails.. Currently my app is kind of slow when the connect fails...
So I would reduce the connect time if it is possible
Thx for any help
Davy
|
|
|
|
|
|
Hi,
I tried to use FormatMessage API to format variable argument that passed to a fuction, but it only delete all '%' characater with no thing else!
please help me.
my code :
void CEllepsisDlg::Log(CString x,...)
{
CString strTempInput;
strTempInput = x;
va_list marker;
va_start( marker, x );
LPTSTR lpFprmatedMessage;
va_start( marker, x );
strTempInput=x;
FormatMessage(FORMAT_MESSAGE_FROM_STRING,
LPCSTR(strTempInput),
NULL,
NULL,
(LPTSTR) &lpFprmatedMessage,
2048,
&marker);
char * tt=(char*)&lpFprmatedMessage;
va_end( marker );
}
|
|
|
|
|
Well looking at your code I think you got the params for FormatMessage slightly wrong. Try changing it to
void CEllepsisDlg::Log(CString x,...)
{
TCHAR fprmatedMessage[2048];
va_list marker;
va_start( marker, x );
FormatMessage(FORMAT_MESSAGE_FROM_STRING, (LPCVOID)((LPCTSTR)x), NULL, NULL,
fprmatedMessage, sizeof(fprmatedMessage), marker);
va_end( marker );
} I havn't tested it, but I think that might work better.
[EDIT]Be aware that in this new scheme that i've created, nothing happens to fprmatedMessage when FormatMessage has finished. Make sure you copy the string into a CString before using outside the Log function, otherwise your program will crash. e.g.
CString myresult = fprmatedMessage; If you only want to use it within the function, then you can use fprmatedMessage just like any LPTSTR.[/EDIT]
Hope this helps.
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|