Solved it! Gotta love when you solve your own problems. Here's how "I" did it....
The 'rundown:
- The external device sends the Checksum's hex value as two separate bytes (Ex: checksum of 0xC7 is sent as ASCII bytes "C" and "7").
- My device calculates its own Checksum based on the received data. My checksum and the checksum I received should match if I got a good read. For this example, my total checksum adds to 0xC7, or decimal 199.
I receive the two checksum bytes into byte variables CS1 and CS2.
CS1 = "C" or 0x43
CS2 = "7" or 0x37
My calculated checksum:
CS_Calc = 0xC7 (199)
Now I must combine CS1 and CS2 into a single hex... I've got to take "C' and "7" and make it 0xC7. This is where all my problems were. How to do it? Here it is....
First, determine (for both CS1 & CS2) if it's a letter or number. The respective subtraction must be done accordingly....
If <= 57, subtract 48
if >= 65, subtract 55
This will convert, say CS1 = "C", which is decimal 67, to a hex = 0xC.... Since 67>65, 67-55=12, which makes CS1 = 0xC.
Do this for both CS1 & CS2.
Lastly, do some math to combine CS1 & CS2 into one byte:
CS1*16 + CS2
For our example, that would be: 12*16 + 7 = 199 = 0xC7 ... PERFECT!!!!
