jokoon
jokoon

Reputation: 6633

Converting a GMP integer to a base N integer

GMP allows to print a mpz_t up to base 62, but I want to represent a number into any base N, and for this I first need to generate an array of integers (let us say I will limit myself to base 2 ^ 64), so an array of unsigned long might do it.

For example if I want to take any integer and convert it to base 792, I can't put it into a string directly, I have to make an array of integers first.

Is there existing code for this in GMP, like some math of some kind I need to learn about or should I start coding it ?

P.S. I know it's totally irrelevant to employ the term 'base' while I could use 'linear vector space', so it makes the conversion pointless, but there a lot of symbols in unicode (95,221 in unicode 3.2), so I could still find a way to represent those with single symbols.

Upvotes: 2

Views: 1381

Answers (1)

Mysticial
Mysticial

Reputation: 471249

Internally, GMP's functions directly or indirectly call the mpn layer - which are documented here:

http://gmplib.org/manual/Low_002dlevel-Functions.html#Low_002dlevel-Functions

The mpn_get_str only supports bases up to 256. So I don't think you can go higher unless you write your own base conversion (which is not trivial at all).

Upvotes: 2

Related Questions