HhhOS/arch/x86_64/std/util.c
2021-08-17 12:45:35 +03:00

46 lines
762 B
C

#include <std/util.h>
static usize rand_next = 1;
int rand(void) {
rand_next = rand_next * 1103515245 + 12345;
return (usize)(rand_next/65536) % 32768;
}
void srand(usize seed) {
rand_next = seed;
}
char* itoa(int res) {
int size = 0;
int t = res;
while(t / 10 != 0) {
t = t/10;
size++;
}
static char ret[64];
size++;
ret[size] = '\0';
t = res;
int i = size - 1;
while(i >= 0) {
ret[i] = (t % 10) + '0';
t = t/10;
i--;
}
return ret;
}
unsigned int atoi(const char *in) {
unsigned int size = 0;
unsigned int j;
unsigned int count = 1;
for (j = 11; j > 0; j--, count *= 8)
size += ((in[j - 1] - '0') * count);
return size;
}