fan_monitor/src/utils.c
Steins7 92784cbe1a Restored previous work
- cleaned up github stuff
+ restored cad data
+ restored graph calculations
+ restored code base
2021-08-14 15:03:01 +02:00

31 lines
526 B
C

#include "utils.h"
uint32_t num2str(char *s, int number, uint8_t base) {
static char hexChars[] = "0123456789ABCDEF";
char *p = s;
// manage sign
uint32_t nb = (number < 0 ? -number : number);
// get digits
do {
*s++ = hexChars[nb % base];
} while (nb /= base);
// finalize string
if(number < 0) *s++ = '-';
*s='\0';
// reverse string
int cnt = s - p;
char tmp;
for(int i=0; i<cnt/2; ++i) {
tmp = p[i];
p[i] = p[cnt-i-1];
p[cnt-i-1] = tmp;
}
return cnt; //number of caracters (excluding '\0')
}