Jump to content
Tuts 4 You

Using bignum library


futureproof

Recommended Posts

futureproof
Posted

I have a function that converts me from any base to base 10 but the result is very long and it cannot be stored in an integer. Can someone explain me how should i use bignum lib so i can print result?

Posted (edited)

Depends on which bignum library you use. For example OpenSSL BigNum lib has functions:


char *BN_bn2hex(const BIGNUM *a);
char *BN_bn2dec(const BIGNUM *a);BN_bn2hex() and BN_bn2dec() return printable strings containing the hexadecimal and decimal encoding of a respectively.
For negative numbers, the string is prefaced with a leading '-'. The string must be freed later using OPENSSL_free().

EDIT: fixed formatting.

Edited by kao
Posted

You really don't want to search, do you?
/>http://gmplib.org/manual/Formatted-Output.html

  • Like 1
Posted (edited)

ISO-C and most C++ compilers support 64bit integer (long long) and their unsigned equivalents. Maybe that's enough for your needs.

unsigned long long ul64 = 1111111122222222ULL;

Edited by Killboy

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...