Convert character to upper-case before converting to decimal
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include "includes/numeric_base.hpp"
|
#include "includes/numeric_base.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
std::string possible_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
std::string possible_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
@@ -15,7 +16,7 @@ unsigned int to_decimal(std::string num, int from_base) {
|
|||||||
compute the value using */
|
compute the value using */
|
||||||
for (int i=0; i < (int)num.length(); i++) {
|
for (int i=0; i < (int)num.length(); i++) {
|
||||||
current_char = num.at(i);
|
current_char = num.at(i);
|
||||||
index = possible_chars.find(current_char);
|
index = possible_chars.find(toupper(current_char)); // Convert the character to upper-case, so that the earliest match is detected
|
||||||
value += pow(from_base, num.length() - i - 1) * index;
|
value += pow(from_base, num.length() - i - 1) * index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user