Add convert_to_base_64 function to convert string integer to magnitudes#34
Add convert_to_base_64 function to convert string integer to magnitudes#34sahmad98 wants to merge 1 commit intofaheel:base-2-to-the-64from
Conversation
7b6df13 to
522f8d7
Compare
faheel
left a comment
There was a problem hiding this comment.
Thanks, but the logic you've used for conversion isn't right.
test/functions/utility.test.cpp
Outdated
|
|
||
| TEST_CASE("Conversion to Base64 magnitudes from String", "[Utility][Helper][Base64]") { | ||
| std::string num = "481482486096808911670147153572883801"; | ||
| // Magnitude should be {11670147153572883801, 4814824860968089} |
There was a problem hiding this comment.
The magnitude is incorrect. It should be {5717256727323176281, 26101217871994095}, since
481482486096808911670147153572883801 = 5717256727323176281⋅(264)0 + 26101217871994095⋅(264)1
include/functions/utility.hpp
Outdated
| try { | ||
| std::string num_slice = num.substr(start_it, stop_it); | ||
| component = std::stoull(num_slice); | ||
| } catch (std::out_of_range& e) { //Using out_of_range to determine overflow |
There was a problem hiding this comment.
This logic wouldn't work. What we want is to divide the number by the largest power of 264 that gives a non-zero quotient, push that in an array, use the remainder as the new number and repeat the process with decreasing powers until we reach 1 (0th power). Then return the reversed array.
There was a problem hiding this comment.
I was wondering how can we divide a number even with 264, the dividend will anyway overflow if we are going to do these in the traditional way. So i am thinking it must all be done in strings rather than converting the numbers into integer chunks or something related.
There was a problem hiding this comment.
Yes, we'll need to do string-based division first to convert to base 264. I'm working on removing as much code as possible while still having string division and remainder work. But it'll take some time as I'm busy with exams currently. In the meanwhile, if you have another suggestion, or would like to work on this then let me know.
There was a problem hiding this comment.
Yes, i will modify it to use string divisions instead.
f5c8b64 to
783828f
Compare
783828f to
2bc7e68
Compare
| magnitude = convert_to_base_2_to_the_64(num_magnitude); | ||
| */ | ||
| magnitude = {0}; | ||
| magnitude = convert_to_base_64(num_magnitude); |
There was a problem hiding this comment.
It seems we have a circular dependency here, because in order to get magnitudes we first need to create a BigInt from string and then get magnitudes by calling a function which returns a magnitude vector, in my case BigInt::to_base64. What are your thoughts on this?
Added a function to convert
BigIntstring representation into Base64 magnitudes. It starts from back of string and checks for overflow if saved into a 64-bit variable, which means we have reached at a point in string which is a component inmagnitudevector, push this component into the vector and then start over again from the current point in string to check for next component.