summaryrefslogtreecommitdiff
path: root/minilib/utils.c
blob: eea07581e32f11f286828705bab38657f17158e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "utils.h"

static char hexdigits[17] = "0123456789abcdef";

void strtohex( char *p, int len, char *s )
{
	while( len > 0 ) {
		char c = *p;
		
		*s = hexdigits[( c >> 4 ) & 0xf];
		s++;
		*s = hexdigits[c & 0xf];
		s++;

		p++;
		len--;
	}
	
	*s = '\0';
}

void inttohex( int i, char *s )
{
	*s = hexdigits[( i >> 4 ) & 0xf];
	s++;
	*s = hexdigits[i & 0xf];
	s++;
	
	*s = '\0';
}