From 2c735896df1e15dab5acccd88970f6a09d9e6e31 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 1 Mar 2024 07:21:03 -0600 Subject: [PATCH] Used unsigned int instead of int when converting to base-10 --- includes/numeric_base.hpp | 4 ++-- numeric_base.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/numeric_base.hpp b/includes/numeric_base.hpp index eced847..522c11b 100644 --- a/includes/numeric_base.hpp +++ b/includes/numeric_base.hpp @@ -3,10 +3,10 @@ #include /* Convert the given value from the given base, to base 10 */ -int to_decimal(std::string num, int from_base); +unsigned 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); +std::string from_decimal(unsigned 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); diff --git a/numeric_base.cpp b/numeric_base.cpp index 4acb52f..309265f 100644 --- a/numeric_base.cpp +++ b/numeric_base.cpp @@ -5,10 +5,10 @@ std::string possible_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -int to_decimal(std::string num, int from_base) { +unsigned int to_decimal(std::string num, int from_base) { char current_char = 0; int index = 0; - int value = 0; + unsigned int value = 0; /* Here, we convert 'num' to decimal (base 10) - Find the index of every character in the string, in 'possible_chars' and @@ -23,7 +23,7 @@ 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) { +std::string from_decimal(unsigned int num, int to_base) { std::string return_val; int val = 0; while (num > 0) { @@ -40,7 +40,7 @@ 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) { - int temp = to_decimal(num, from_base); + unsigned int temp = to_decimal(num, from_base); std::string result = from_decimal(temp, to_base); return result;