feature (kernel utils): implemented octal_string to integer conversion

This commit is contained in:
antifallobst 2023-02-27 22:40:22 +01:00
parent ace8f2eb0e
commit 400deaef91
2 changed files with 13 additions and 2 deletions

View File

@ -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)
@ -36,7 +37,8 @@ typedef struct {
uint64_t y;
} position_T;
uint64_t pow(uint64_t base, uint64_t exp);
uint64_t abs(int64_t n);
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

View File

@ -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;
}