From 13da0156835b2d74474b4696ada2a0459c66042f Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 15 Feb 2024 09:13:51 -0500 Subject: [PATCH] Renamed base-helpers to numeric_base, and separated numeric_base into header and implementation files --- includes/numeric_base.hpp | 14 ++++++++++++++ includes/base-helpers.hpp => numeric_base.cpp | 7 ++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 includes/numeric_base.hpp rename includes/base-helpers.hpp => numeric_base.cpp (90%) diff --git a/includes/numeric_base.hpp b/includes/numeric_base.hpp new file mode 100644 index 0000000..eced847 --- /dev/null +++ b/includes/numeric_base.hpp @@ -0,0 +1,14 @@ +#ifndef _BASE_HELP +#define _BASE_HELP +#include + +/* 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 diff --git a/includes/base-helpers.hpp b/numeric_base.cpp similarity index 90% rename from includes/base-helpers.hpp rename to numeric_base.cpp index 1c79dfd..4acb52f 100644 --- a/includes/base-helpers.hpp +++ b/numeric_base.cpp @@ -1,13 +1,10 @@ -#ifndef _BASE_HELP -#define _BASE_HELP +#include "includes/numeric_base.hpp" #include #include -#include #include 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 +