Hi everyone...had a quick question regarding converting some received data into ASCII.
Ive googled this for the past couple hours and there are tons of "converting between ASCII/hex/decimal" threads, but none seem to quite match what Im trying to do as far as splitting up the two characters that make up one byte in hex.
I have to perform several steps here.
Convert a 0-255 decimal byte value into a 0x00-0xFF hex character.
Convert the two letter hex character into two separate ASCII values, representing the number/letter of each hex character.
starting with: byte myByte = 156 decimal
decimal 156 = 0x9C hex
Convert 0x9C into two separate ASCII characters "9" and "C"
Convert ASCII 9 and ASCII C back into either decimal or hex values.
myConvertedByte1 = 57 (hex 0x39, ASCII 9)
myConvertedByte2 = 67 (hex 0x43, ASCII C)
Maybe bitRead the 4 most significant bits, then the 4 least significant bits.....then if its decimal 10, 11, 12, 13, 14, 15...add 55...and that will get ASCII A, B, C, D, E, F. If the 4 bits decimal value is less than 10....add 48....and that will get ASCII 1, 2, 3, 4, 5, 6, 7, 8?
Seems awfully clunky and complicated though...there has to be a nice simple way??
(what im actually trying to do is read in 2 bytes of a CAN-bus message, and then convert those 2 bytes into 4 separate ASCII characters).
This is outputted ASCII is NOT for use with displaying data to the arduino serial terminal or an LCD, so I cant just use "Serial.println(myByte, HEX)" or something.