#i nclude <stdio.h>
#i nclude <string.h>
code unsigned char mul_str[]={4,2,9,4,9,6,7,2,9,6,0};//2^32
/*------------------------------------------------------------------------------
Name : int2str_64b
Deion : convert 64bit integer to string
Parameters :
Input : unsigned long High: Higher 32bits of the integer
unsigned long Low : Lower 32bits of the integer
Output : unsigned char *result : the pointer to the result, max_length = 21 bytes
Return : length of the string
------------------------------------------------------------------------------*/
unsigned char int2str_64b(unsigned long High, unsigned long Low, unsigned char *result)
{
unsigned char tmp_str[11];
unsigned char i, j, k, inc, tmp;
//high * 2^32
memset(result, 0, 21);
sprintf(tmp_str, "%010lu", High);
for(i = 0; i < 10; i++)
tmp_str -= '0';
for(i = 10; i > 0; i--){
for(j = 10; j > 0; j--){
k = i + j - 1;
inc = 0;
tmp = tmp_str[i - 1] * mul_str[j - 1] + result[k];
inc = tmp / 10;
result[k] = tmp % 10;
while(inc != 0){
k--;
tmp = result[k] + inc;
result[k] = tmp % 10;
inc = tmp / 10;
}
}
}
// result + low
sprintf(tmp_str, "%010lu", Low);
for(i = 0; i < 10; i++)
tmp_str -= '0';
inc = 0;
for(i = 10; i > 0; i--){
tmp = result[i + 9] + tmp_str[i - 1] + inc;
inc = tmp / 10;
result[i + 9] = tmp % 10;
}
k = 10;
while(inc != 0){
k--;
tmp = result[k] + inc;
inc = tmp / 10;
result[k] = tmp % 10;
}
//remove addtional 0s
for(i = 0;i < 19; i++)
if(result != 0)
break;
for(j = i; j < 20; j++){
result[j - i] = result[j] + '0';
}
result[20 - i] = 0;
return (20 - i);
}
//---------------------------------------------------------------------------------------------