feature (kernel utils): implemented octal_string to integer conversion
This commit is contained in:
parent
ace8f2eb0e
commit
400deaef91
|
@ -25,6 +25,7 @@
|
|||
#define NOX_MATH_H
|
||||
|
||||
#include "stdtypes.h"
|
||||
#include "string.h"
|
||||
|
||||
#define MAX(a, b) (a > b ? a : b)
|
||||
#define MIN(a, b) (a > b ? b : a)
|
||||
|
@ -38,5 +39,6 @@ typedef struct {
|
|||
|
||||
uint64_t pow (uint64_t base, uint64_t exp);
|
||||
uint64_t abs (int64_t n);
|
||||
uint64_t octal_string_to_int (string_t string, uint8_t size);
|
||||
|
||||
#endif //NOX_MATH_H
|
||||
|
|
|
@ -37,3 +37,12 @@ uint64_t abs(int64_t n) {
|
|||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
uint64_t octal_string_to_int(string_t string, uint8_t size) {
|
||||
uint64_t n = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
n *= 8;
|
||||
n += string[i] - '0';
|
||||
}
|
||||
return n;
|
||||
}
|
Loading…
Reference in New Issue