[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bottleneck: string2hex
- From: Florian Weimer <fw@...>
- Date: Sat, 17 Apr 2010 17:18:47 +0200
* Michal Kottman:
> Another (faster) alternative is to avoid the sprintf() call and
> calculate hex string directly:
>
> static char hex[] = "0123456789ABCDEF";
>
> ...
>
> for ( p = ns , max = size ; max > 0 ; max--)
> {
> *p++ = hex[*s >> 4];
> *p++ = hex[*s++ & 0xF];
> }
Caution: this doesn't work with signed chars, you have to change s to
a pointer to an unsigned char in Sean's code.