CBFalconer said:
I suspect this may be beyond you, but take a look at dubldabl.
<
http://cbfalconer.home.att.net/download>
Correct me if i am wrong but, I dont think that this will work, because
in my case i have array of binary coded numbers but each element in the
array corresponds to a base not equal to 2^bits per field.
That is, my data looks like this
2^70 2^60 2^50 2^40 2^30 2^20 2^10
2^0
-----------------------------------------------------------------------------------------------------
| 0-1023 | 0-1023 | 0-1023 | 0-1023 | 0-1023 | 0-1023 | 0-1023 | 0-1023
|
-----------------------------------------------------------------------------------------------------
|4 bytes |4 bytes |4 bytes |4 bytes |4 bytes |4 bytes |4 bytes |4 bytes
|
-----------------------------------------------------------------------------------------------------
theoretically the range of each field can be half the bits in the
field. This has to be so to allow for an integer datatype to be able to
hold a maximum product of 2 fields.
so if i were to setup something like:
--------------------------------------------------------------------------------------------
| ASCII Memory | Binary Memory
|
--------------------------------------------------------------------------------------------
and shift from right 2 left using algorythm you pointed me to,
shouldn't the unused 2 left bytes of each element in binary memeory
screw up the ASII memory?
Before you posted the post to which i am replying here, i tried to
print the numbers into char array, as follows:
base = 1024
===================Start Code=======================
void AEIprintf(struct AEI *p) {
int fieldLength = (int)log10(base);
long fieldbase=pow(10,fieldLength+1), N=0, carry=0, tbl=0;
char format[10], *buffer;
long j = p->digits;
long i=0;
buffer=malloc(sizeof(struct AEI)*10);
if(buffer!=NULL){
while(i<j){
N=(carry+p->data
+p->data[i+1]*base)%fieldbase;
carry=(carry+p->data+p->data[i+1]*base)/fieldbase;
tbl+=sprintf(buffer+tbl,"%ld",N);
i++;
}
printf("\nprinting buffer %d\n", strlen(buffer));
printf("\n%s\n",buffer);
}else{
printf("\nCant Allocate memory\n");
}
return;
}
===================End Code========================
but because the base has integer value in it 1024 the contribution to
units decemal field of resulting number in base 10 will come from all
elements of array in base 1024 i would have to find (p->data[N])*1024^N
which is impossible to do since N is several thousand may be even 10s
of thousands.
It is also the case that even if i were to requre the field size be
half of the bits of the maximun int type, hence allowing to use all
bits in the field to store data, to not wory about separate sign field,
i casted the array as signed, i know its wastefull, but i have not
thought of the way to handle it oherwise, i guess it can be done adding
a sign field into the structure.
what would you seggest about printing function?
The more I am thinking about the more it seems that i should redo it
using unsigned ints using full field width, but i have not yet gathereg
my bravory to do that.