BigInt is a small C++20 library for unsigned big-integer arithmetic using 64-bit limb storage. It was developed for use in RSA-Encryptor and is intended to be integrated as a Git submodule.
The library provides arithmetic for numbers that can grow beyond native integer
limits such as uint64_t. This makes it useful for cryptographic-style
calculations where values often need more than the CPU's built-in integer width.
operations::BigInt stores a number as a dynamically sized ByteArray
(std::vector<uint64_t>). Each limb is one base-2^64 digit:
- index
0contains the least-significant limb - index
1contains the next(2^64)^1limb - higher indexes continue the same little-endian layout
After arithmetic operations, the internal limb array is normalized by removing unused high zero-limbs while keeping zero represented as a single limb.
For a deeper explanation of the internal representation, see
docs/bigint.md.
#include "bigint.h"
#include "math_utils.h"
using operations::BigInt;
using operations::math::pow;
int main() {
BigInt a(4294967295ULL);
BigInt b(2);
BigInt sum = a + b;
BigInt product = a * b;
BigInt remainder = product % b;
BigInt power = pow(b, 16);
power.print();
}The class supports construction from uint64_t, arithmetic operators
+, -, *, /, %, compound assignments, comparisons, operations::math::pow, and
decimal output with print().
Add this repository to your parent project and include it with CMake:
add_subdirectory(lib/BigInt)
target_link_libraries(YourTarget PRIVATE BigInt)If your parent project does not already expose the library headers, add the
submodule's src directory to your include path.
Note
BigInt is a library, not a standalone executable. The library code itself is meant to be used from another program. The tests, however, can be built and run directly from this repository without integrating BigInt into another project.
Tests are enabled for Debug builds:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
ctest --test-dir build --output-on-failure