# Thread: 128-bit number to senary (base 6) efficient tranlation

1. ## 128-bit number to senary (base 6) efficient tranlation

I have to translate one 128-bit-long number (witch is stored in 16 separate bytes in one array) to a senary (base 6) 25-byte-long char (ascii) string ('0'....'5'). I am looking for code consuming the least memory space posible as this would be implemented in an mcu with very little recources (ram is below 1kb). 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.

2. Hmm, do you know how to convert from decimal to base 6? You just modulate the number by 6, and use that value as the base6 index to get the correct character, than divide the value by 6.

Code:
```int main()
{
char out[25] = {0};
int testVal = 393;
const char base6[6] = {
'0', '1', '2', '3', '4', '5'
};

char* ptr = &out[24];
for(; ptr >= out; --ptr)
{
*ptr = base6[testVal &#37; 6];
testVal /= 6;
}

//test the result
size_t i = 0;
while(i < sizeof(out))
printf("%c", out[i++]);

return 0;
}```
It requires a bit more to convert a large number like 128-bit.

3. With this method I need only 24 divisions with 6 to produce the base-6 number. Of cource I can't handle the 128-bit data at once, I have to separate the division-cycle to 16 sub-divisions for each byte of the array. But I can handle this. Great!
(As far as now I don't ever use the modulus operator, and I have done number to decade-char translations with my own custom code) This is far more efficient, thank you!