Renamed base-helpers to numeric_base, and separated numeric_base into header and implementation files

This commit is contained in:
2024-02-15 09:13:51 -05:00
parent a47e598b5c
commit 13da015683
2 changed files with 16 additions and 5 deletions

14
includes/numeric_base.hpp Normal file
View File

@@ -0,0 +1,14 @@
#ifndef _BASE_HELP
#define _BASE_HELP
#include <string>
/* Convert the given value from the given base, to base 10 */
int to_decimal(std::string num, int from_base);
/* Convert the given value from base 10 to the given base */
std::string from_decimal(int num, int to_base);
/* Convert the given value from 'from_base', to 'to_base' */
std::string base_convert(std::string num, int from_base, int to_base);
#endif

View File

@@ -1,13 +1,10 @@
#ifndef _BASE_HELP
#define _BASE_HELP
#include "includes/numeric_base.hpp"
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
std::string possible_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/* Convert the given value from the given base, to base 10 */
int to_decimal(std::string num, int from_base) {
char current_char = 0;
int index = 0;
@@ -48,4 +45,4 @@ std::string base_convert(std::string num, int from_base, int to_base) {
return result;
}
#endif