1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-12-11 21:13:00 +01:00

fix: convert numbers base to another only accept unsigned integers

This commit is contained in:
Théo LUDWIG 2023-08-09 23:29:58 +02:00
parent b9ba3fbff4
commit 07e2f4db45
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
2 changed files with 8 additions and 8 deletions

View File

@ -62,7 +62,7 @@ string_t convert_number_to_string(const long long integer) {
return string; 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) { if (number == 0) {
return "0"; return "0";
} }
@ -88,10 +88,10 @@ string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned
return result; return result;
} }
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) {
int length = string_get_length(number); size_t length = string_get_length(number);
int exponent = length - 1; int exponent = length - 1;
int result = 0; unsigned long result = 0;
int index = 0; int index = 0;
while (exponent >= 0) { while (exponent >= 0) {
int current_number = (int)(number[index] - '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; 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); return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target);
} }

View File

@ -64,7 +64,7 @@ string_t convert_number_to_string(const long long integer);
* @return string_t * @return string_t
* @since v1.0.0 * @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. * @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 * @return int
* @since v1.0.0 * @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. * @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 * @return string_t
* @since v1.0.0 * @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 #endif