lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


* 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.