Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Interesting numbers about hashing - 32 bits are clearly not enough

Author: Uri Blass

Date: 06:44:41 12/07/01

Go up one level in this thread


On December 07, 2001 at 09:39:45, Uri Blass wrote:

>On December 07, 2001 at 09:25:57, Uri Blass wrote:
>
>>On December 07, 2001 at 09:17:01, Sune Fischer wrote:
>>
>>>On December 07, 2001 at 09:00:27, Uri Blass wrote:
>>>>I got the following function but it simply does not work
>>>>
>>>>char * tostring (__int64 x, char *s)
>>>>{ __int64 a = x/1000000;
>>>>  __int64 b = x%1000000;
>>>>  if (x>1000000)
>>>>     sprintf(s,"%d%d",a,b);
>>>>  else
>>>>     sprintf(s,"%d",b);
>>>>  return s;
>>>>}
>>>>
>>>>I tested my program by the following code
>>>>char buffer[64];
>>>>__int64 mone;
>>>>mone=(1<<30);
>>>>printf("mone: %s\n",tostring(mone,buffer));
>>>>
>>>>and I get the wrong output 10730 when the right output should be 2^30=1073741824
>>>>
>>>>Uri
>>>
>>>Don't you need to make a cast first:
>>>__int64 b = x%((__int64)1000000);
>>>?
>>
>>I tried here
>>Here is my newcode and it does not help
>>
>>char * tostring (__int64 x, char *s)
>>{ __int64 a = x/((__int64) 1000000);
>>  __int64 b = x%((__int64) 1000000);
>>  if (x>1000000)
>>     sprintf(s,"%d%d",a,b);
>>  else
>>     sprintf(s,"%d",b);
>>  return s;
>>}
>>
>>and later in main.c
>>
>>char buffer[64];
>>mone=(1<<30);
>>printf("mone: %s\n",tostring(mone,buffer));
>>
>>I get again the same wrong number 10730 on the screen.
>>
>>My previous code without strings worked well so I guess I will go back to my
>>previous code except maybe using mone%1000000 instead of
>>mone-1000000*(mone/1000000);
>>
>>Uri
>
>Here is a better code to print a 64 bit number p when mone is also defined to be
>a 64 bit number
>
>I tested it and it seems to work
>mone=p;
>printf("      %d",mone/1000000);
>	mone=mone%1000000;
>	i=5;
>	while (mone<(10<<i)&&i>0)
>	{
>		printf("0");
>		i--;
>	}
>printf("%d",mone);
>
>Uri

The only problem that I see is printing 0's before the number when the number is
small but I do not consider it as important(I can change it by one if)

Uri



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.