|
BigDigits C++ OOP
1.0.1
|
This is the C++ object-oriented interface to the BigDigits library. It requires C++11 or later. It uses no external libraries except the standard ones.
The core is the BigDigit class which can represent large non-negative integers up to the memory limits of your machine.
This C++ OOP code is a wrapper around the original ANSI C BigDigits "bd" code. It uses operator overloading, which replaces all the "bd" functions which added, shifted or compared BIGD values with C++ overloaded operators, all with their original meaning.
+ - * / % += -= *= /= %= & &= | |= << >> <<= >>= ~ ++ -- < <= == >= >
In general, the BigDigit methods do not modify the object's value, except for those methods beginning with "set".
Memory for BigDigit objects is automatically freed, unless the program is aborted.
The BigDigits library is provided free of charge under a MPL-2.0 license. You can download it from https://di-mgt.com.au/bigdigits.html.
Embed the header for dibigd.hpp in your main file. Set the values of BigDigit objects using the constructor form, a direct assign, or the from_str() function.
The only exceptions thrown are std::runtime_error when
and std::invalid_argument if an invalid character is found when using dibigd::from_str() or dibigd::Bvec::from_hex().
To compile your source code, say, mycode.cpp, have the following files present when compiling
The files bigdall.c and bigdall.h are a convenient merge of all the separate source and include files needed for the ANSI C BigDigits "bd" interface.
Using the Visual Studio IDE, make sure you use the Default compile language option, so both .c and .cpp files compile properly.
Using the MSVC command line
Use /DNO_WINGUI to avoid having to link to user32.lib, and /EHsc to enable C++ exceptions. Do not use either of the /TC or /TP compile flags.
Using gcc, compile the .c file separately using gcc and then use g++ to compile the .cpp sources.
Utilities are provided to convert between the BigDigit integer type and an array of bytes (octets), stored in std::vector<unsigned char>.
The dibigd::BigDigit::to_octets method takes the bitstring representation of a BigDigit object in big-endian order (most significant bit first) and splits into 8-bit octets reading left to right. The number of octets to be decoded can be specified to ensure leading zero octets are included. dibigd::BigDigit::from_octets does the reverse, but leading zero octets are ignored.
Note the significance of leading zeros when decoding from a string representation.