Files
SDK_SG200x_V2/fsbl/lib/stdlib/misc.c
carbon 0545e9dc6d init version 2024-05-07
commit d1edce71135cc6d98c0a4b5729774542b676e769
Author: sophgo-forum-service <forum_service@sophgo.com>
Date:   Fri Mar 15 16:07:33 2024 +0800

    [fix] recommend using ssh method to clone repo.
    [fix] fix sensor driver repo branch name.
2024-05-07 19:36:36 +08:00

43 lines
703 B
C

#include <stdint.h>
#include <ctype.h>
#include <string.h>
#define MAXNBUF (sizeof(intmax_t) * 8 + 1)
char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
#define hex2ascii(hex) (hex2ascii_data[hex])
char *ntostr(char *nbuf, uintmax_t num, int _base, int upper)
{
typeof(num) base = (typeof(base))_base;
char *p, *q, c;
p = q = nbuf;
*p = '\0';
do {
c = hex2ascii(num % base);
*++p = upper ? (char)toupper(c) : c;
} while (num /= base);
while (q < p) {
c = *q;
*q++ = *p;
*p-- = c;
}
return p;
}
void bytes_reverse(void *buf, size_t n)
{
uint8_t t, *a = buf;
int i, j;
for (i = 0, j = n - 1; i < j; i++, j--) {
t = a[i];
a[i] = a[j];
a[j] = t;
}
}