??? 05/07/08 22:34 Read: times |
#154553 - C does know ASCII Responding to: ???'s previous message |
Chris Bertrand said:
it kept messing me up because if the 'B' was getting the ASCII value The C programming language will always interpret a single-character constant such as 'B' using the character encoding of the underlying architecture - which usually happens to be ASCII. Thus Brett's code unsigned char Hex2Ascii(unsigned char HexValue) { HexValue &= 0x0F; // Mask-off the upper nibble if (HexValue <= 0x09) // For values 0x00 - 0x09 { return(HexValue + 0x30); // Return the ascii code for the digits } else // For values 0x0A - 0x0F { return(HexValue + 0x37); // Return the upper case ascii codes } } unsigned char Hex2Ascii(unsigned char HexValue) { HexValue &= 0x0F; // Mask-off the upper nibble if (HexValue <= 0x09) // For values 0x00 - 0x09 { return(HexValue + '0'); // Return the ascii code for the digits } else // For values 0x0A - 0x0F { return((HexValue-10) + 'A'); // Return the upper case ascii codes } } |