From 400deaef9106ce8c44b610935523bcce9e27ea9b Mon Sep 17 00:00:00 2001 From: antifallobst Date: Mon, 27 Feb 2023 22:40:22 +0100 Subject: [PATCH] feature (kernel utils): implemented octal_string to integer conversion --- kernel/inc/utils/math.h | 6 ++++-- kernel/src/utils/math.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/inc/utils/math.h b/kernel/inc/utils/math.h index 69e8446..26d3cea 100644 --- a/kernel/inc/utils/math.h +++ b/kernel/inc/utils/math.h @@ -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 diff --git a/kernel/src/utils/math.c b/kernel/src/utils/math.c index ad74787..b4c60dc 100644 --- a/kernel/src/utils/math.c +++ b/kernel/src/utils/math.c @@ -36,4 +36,13 @@ uint64_t abs(int64_t n) { return n * -1; } 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; } \ No newline at end of file