Bigint

The C implementation of big integer.

Usage

Include bigint.h.

To convert a string to a bigint:

const char* s = "9304294823748978957892374892374983274239871";
bigint* bi = BINT_atoi(s);

To convert a bigint back to a string:

char* s = BINT_itoa(bi);
printf("%s\n", s);
free(s);

Remember to free the string because it is malloced.

To create a bigint from bytes (uint8 array),

size_t sz = 100;
uint8_t* arr = malloc(sizeof(uint8_t) * 100);
bigint* bi = BINT_makep(arr, sz);

Remember to free the bigint after using.

BINT_free(bi);

Arithmetic functions:

  • BINT_add: only supports non-negative now.
bigint* a = BINT_atoi("41574280935842903589085243");
bigint* b = BINT_atoi("3284923071943289748237424428520");
bigint* res = BINT_make(); // makes an empty bigint for result
BINT_add(a, b, res); // res = a + b
  • BINT_mul
bigint* res = BINT_make(); // makes an empty bigint for result
BINT_mul(a, b, res); // res = a * b