K
Keith Thompson
David Thompson said:[...]Maybe it's just me, but I'd (also?) put the more significant nibble inNote that any 2-digit string literal would do. If I were going to
use this approach, I'd probably omit the initialization and add
b[2] = '\0';
at the end. (I'd also assign to b[0] before b[1], but that doesn't
really matter.)
b[1] = (unsigned char)c / 16;
b[1] += (b[1] < 10)? '0': 'A';
b[0] = (unsigned char)c % 16;
b[0] += (b[0] < 10)? '0': 'A';
b[0] and the less in b[1]. Or if that's what you meant, I don't think
you were clear about it. (Forest for trees maybe?)
I wasn't thinking about which nibble should go where, just that
assigning to b[1] first and b[0] second seemed odd.