Addressing single digits of big integers

decio at decio at
Sat Jul 26 00:29:08 CEST 2008

----- Original Message -----
From: "Rafael Anschau" <rafael.anschau at>
To: gmp-discuss at
Subject: Addressing single digits of big integers
Date: Thu, 24 Jul 2008 16:48:03 -0300

> Is it possible to address single digits in big integers,
> without the high costs of export import ? Something like a
> pointer to the digit ?

If by digit you mean a base-10 digit, sorry, it's gonna be
fairly costly. Most large integer packages represent values
internally in a power-of-two base, so you can't directly get
base-10 digits, only base-2^k digits. To get base-10 digits
you'll have to incur the cost of changing representation by
exporting, or doing a calculation like x/10^k mod 10, and
both the division and the modulo are costly for large

If you routinely need to work with the base-10
representation of your large integers, and it's a bottleneck
of your code (profile it somewhere to be sure, otherwise you
may lose performance by following this advice), try a
different library which works with a power-of-10 base
representation. I can't name any, but I know that most of
the various Pi-calculator programs out there use base-10
extensively to avoid a costly change of representation at
the end.


More information about the gmp-discuss mailing list