shithub: femtolisp

ref: 7dbce0093820a01a64d40ce09fee3ef9fecc5f9c
dir: /llt/int2str.c/

View raw version
#include "llt.h"

char *
uint2str(char *dest, size_t len, uint64_t num, uint32_t base)
{
	int i = len-1;
	uint64_t b = (uint64_t)base;
	char ch;
	dest[i--] = '\0';
	while(i >= 0){
		ch = (char)(num % b);
		if(ch < 10)
			ch += '0';
		else
			ch = ch-10+'a';
		dest[i--] = ch;
		num /= b;
		if(num == 0)
			break;
	}
	return &dest[i+1];
}

int
isdigit_base(char c, int base)
{
	if(base < 11)
		return c >= '0' && c < '0'+base;
	return (c >= '0' && c <= '9') || (c >= 'a' && c < 'a'+base-10) || (c >= 'A' && c < 'A'+base-10);
}