File tree Expand file tree Collapse file tree 4 files changed +21
-12
lines changed
Expand file tree Collapse file tree 4 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ class BigInt {
100100 int to_int () const ;
101101 long to_long () const ;
102102 long long to_long_long () const ;
103+ std::std::vector<uint64_t > to_base64 ();
103104
104105 // Random number generating functions:
105106 friend BigInt big_random (size_t );
Original file line number Diff line number Diff line change @@ -53,12 +53,7 @@ BigInt::BigInt(const std::string& num) {
5353 if (num[0 ] == ' +' or num[0 ] == ' -' ) { // check for sign
5454 std::string num_magnitude = num.substr (1 );
5555 if (is_valid_number (num_magnitude)) {
56- /*
57- TODO
58- ----
59- magnitude = convert_to_base_2_to_the_64(num_magnitude);
60- */
61- magnitude = {0 };
56+ magnitude = convert_to_base_64 (num_magnitude);
6257 is_negative = num[0 ] == ' -' ;
6358 }
6459 else {
@@ -67,12 +62,8 @@ BigInt::BigInt(const std::string& num) {
6762 }
6863 else { // if no sign is specified
6964 if (is_valid_number (num)) {
70- /*
71- TODO
72- ----
73- magnitude = convert_to_base_2_to_the_64(num_magnitude);
74- */
75- magnitude = {0 };
65+ std::string num_magnitude (num);
66+ magnitude = convert_to_base_64 (num_magnitude);
7667 is_negative = false ; // positive by default
7768 }
7869 else {
Original file line number Diff line number Diff line change @@ -58,4 +58,20 @@ long long BigInt::to_long_long() const {
5858 return std::stoll (this ->to_string ());
5959}
6060
61+ /*
62+ to_base64
63+ ---------
64+ Convers a BigInt to its base64 representation
65+ */
66+
67+ std::vector<uint64_t > BigInt::to_base64 () {
68+ std::vector<uint64_t > magnitude;
69+ BigInt max_number (" 18446744073709551616" ); // 2^64 for base conversion
70+ while (*this != 0 ) {
71+ magnitude.push_back (*this % max_number);
72+ *this /= max_number;
73+ }
74+ return magnitude;
75+ };
76+
6177#endif // BIG_INT_CONVERSION_FUNCTIONS_HPP
Original file line number Diff line number Diff line change 88#define BIG_INT_UTILITY_FUNCTIONS_HPP
99
1010#include < tuple>
11+ #include < BigInt.hpp>
1112
1213
1314/*
You can’t perform that action at this time.
0 commit comments