t_maggot
Joined: 09 Nov 2006 Posts: 45 Helped: 2
|
05 Jun 2008 17:40 128-bit hex to senary (base 6) efficient tranlation in c |
|
|
|
|
I have to translate one 128-bit-long number (witch is stored in 16 separate bytes in an array) to a senary (base 6) 25-byte-long char (ascii) string. I am looking for code consuming the least memory space posible. In fact I wonder that maybe there is a way to do this translation without using at all long data types, extended divisions etc.
Any help or directions appreciated.
Added after 4 hours 17 minutes:
Ok, I have found a way to get the number with (24*16) integer divisions with 6, using 7 byte-words as temporary data. This can do the job for me, but if anyone has a better way, you're welcome!
|
|
wek
Joined: 21 Dec 2004 Posts: 239 Helped: 26
|
09 Jun 2008 7:57 128-bit hex to senary (base 6) efficient tranlation in c |
|
|
|
|
You can try the trick used for conversion from bin to decimal: for each bit in the decimal number, multiply the senary number by two (e.g. multiply each digit by two, add carry from lower order, if result >= 6, set carry and perform mod 6) and add the bit from decimal number to the least significant digit of the senary word.
This tends to be rather slow but requires a minimum memory and no division just shifts, thus is suitable for arbitrarily long words.
JW
|
|