On 31 Jan 2012 at 11:21, Sean Conner wrote:
A friend recently raised an issue with some code I wrote (a hex dump
routine) saying it depended upon ASCII and thus, would break on
non-ASCII based systems (and proposed a solution, but that's beside
the issue here). I wrote back, saying the code in question was
non-portable to begin with (since it depended upon read() and
write()---it was targetted at Posix based systems) and besides, I've
never encountered a non-ASCII system in the nearly 30 years I've been
using computers.
I have, but then then I've been at this longer.
In particular, what bit of code did your friend object to?
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).
-spc (But he did mention non-ASCII based systems as the basis for his
complaint)