mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-11-12 15:23:12 +01:00
fix: convert numbers base to another only accept unsigned integers
This commit is contained in:
parent
b9ba3fbff4
commit
07e2f4db45
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user