On 31 Jan 2012 at 13:05, Sean Conner wrote:
while(size--)
{
dest[size] = (char)((value & 0x0F) + '0');
if (dest[size] > '9') dest[size] += 7;
value >>= 4;
}
He suggested the "0123456789ABCDEF"[value & 0x0F] approach (as did a
few others here).
His approach is better--and probably faster on most hardware--and
it's certainly clearer to someone reading the code. It also leaves
you with the ability to make substitutions for characters (e.g.
lowercase instead of uppercase).
Does C require 8-bit byte addressability? Are other "byte" lengths
permitted, such as 9 bits for system using 36 bit words?
--Chuck