From 07e2f4db455c1b7591acbb8aac461b5aa5d879ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Wed, 9 Aug 2023 23:29:58 +0200 Subject: [PATCH] fix: convert numbers base to another only accept unsigned integers --- lib/convert.c | 10 +++++----- lib/convert.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/convert.c b/lib/convert.c index c39bc80..20d995b 100644 --- a/lib/convert.c +++ b/lib/convert.c @@ -62,7 +62,7 @@ string_t convert_number_to_string(const long long integer) { return string; } -string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned int base) { +string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned long base) { if (number == 0) { return "0"; } @@ -88,10 +88,10 @@ string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned return result; } -int convert_number_from_base_to_base_10(string_t number, unsigned int base) { - int length = string_get_length(number); +unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base) { + size_t length = string_get_length(number); int exponent = length - 1; - int result = 0; + unsigned long result = 0; int index = 0; while (exponent >= 0) { int current_number = (int)(number[index] - '0'); @@ -107,6 +107,6 @@ int convert_number_from_base_to_base_10(string_t number, unsigned int base) { return result; } -string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target) { +string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target) { return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target); } diff --git a/lib/convert.h b/lib/convert.h index 1ad93ef..b1dc1e8 100644 --- a/lib/convert.h +++ b/lib/convert.h @@ -64,7 +64,7 @@ string_t convert_number_to_string(const long long integer); * @return string_t * @since v1.0.0 */ -string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned int base); +string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned long base); /** * @brief Convert a number with a specific base to a number base 10. @@ -74,7 +74,7 @@ string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned * @return int * @since v1.0.0 */ -int convert_number_from_base_to_base_10(string_t number, unsigned int base); +unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base); /** * @brief Convert a number with a specific base to a number of specific base. @@ -85,6 +85,6 @@ int convert_number_from_base_to_base_10(string_t number, unsigned int base); * @return string_t * @since v1.0.0 */ -string_t convert_number_from_base_to_another(string_t number, int base_from, int base_target); +string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target); #endif