X-Git-Url: https://mattmccutchen.net/bigint/bigint.git/blobdiff_plain/00c6448a6c5fc7a68427ca1dc3f5f523563e1041..0551c03b5862aafe7f5f88cf282ebf96621c6c80:/sample.cc diff --git a/sample.cc b/sample.cc index 9a75175..f52a7e1 100644 --- a/sample.cc +++ b/sample.cc @@ -62,10 +62,17 @@ int main() { * ``put-here operations''; see `BigUnsigned.hh' for details. */ BigInteger g(314159), h(265); - // All five ``return-by-value'' operators. + // All five ``return-by-value'' arithmetic operators. std::cout << (g + h) << '\n' << (g - h) << '\n' << (g * h) << '\n' << (g / h) << '\n' << (g % h) << std::endl; + BigUnsigned i(0xFF0000FF), j(0x0000FFFF); + // All five ``return-by-value'' bitwise operators. + std::cout.flags(std::ios::hex | std::ios::showbase); + std::cout << (i & j) << '\n' << (i | j) << '\n' << (i ^ j) << '\n' + << (j << 21) << '\n' << (j >> 10) << '\n'; + std::cout.flags(std::ios::dec); + // Let's do some heavy lifting and calculate powers of 314. int maxPower = 10; BigUnsigned x(1), big314(314); @@ -78,7 +85,7 @@ int main() { * If you want to experiment with the library, * you can add your own test code here. */ - // std::cout << "Beginning of custom test code:\n" << std::endl; + // std::cout << "Beginning of custom test code:" << std::endl; } catch(char const* err) { std::cout << "The library threw an exception:\n" @@ -97,6 +104,11 @@ Running the sample program produces this output: 83252135 1185 134 +0xFF +0xFF00FFFF +0xFF00FF00 +0x1FFFE00000 +0x3F 314^0 = 1 314^1 = 314 314^2 = 98596