??? 05/08/08 19:32 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#154589 - How the small trick works Responding to: ???'s previous message |
Russ said:
return "0123456789ABCDEF"[HexValue]; Chris said:
Russ, what is that doing? The quoted string makes a 17-byte array of characters somewhere in memory that contains each of the 16 possible hex digits, followed by a single byte of all zeros that terminates the string. The syntax given then simply returns the element of that array that's indexed by 'HexValue'. The net effect is a mini lookup table, much as if you'd defined the table explicitly, like this: char hexDigits[] = "0123456789ABCDEF"; return hexDigits[HexValue];This trick is standard C stuff, and works just fine, as you have demonstrated. Whether or not it is actually a good trick is debatable, for at least a couple of reasons:
|