I have 58 Sound FX, Music, and Voice files of 2-Digit HEX Audio data that I have stored into Flash Memory(W25Q64-JV) for a 2nd version of a Game I'm building. My program, using Arduino Nano, converts the HEX to Binary and writes it to the Flash. Then, during game-play, it reads from the W25Q64 and streams the Sound to a resistor-ladder, then into my OpAmp. Everything works great.
I found this code(below) for the conversion.
Example Data --> 7F7B808182..... (This is just a txt file.)
(I grab 2 Bytes at a time) Example Data --> hexValue[0]='7' and hexValue[1]='F'.
hexValue[0]=dataFile.read(); // Read 1st Hex Digit.
hexValue[1]=dataFile.read(); // Read 2nd Hex Digit.
Using code that works is one thing, but understanding it is another. I want to understand this below, but can't find any explanation online.
byte tens = (hexValue[0] < '9') ? hexValue[0] - '0' : hexValue[0] - '7'; (Why does this work? )
byte ones = (hexValue[1] < '9') ? hexValue[1] - '0' : hexValue[1] - '7'; (Why does this work? )
byte number = (16 * tens) + ones; (I understand this.)
I understand the last line, simple HEX math. But the 2 above that confuse me. It appears to be some kind of conditional statement, but It confuses me. Any feedback would be appreciated. Thanks.
I found this code(below) for the conversion.
Example Data --> 7F7B808182..... (This is just a txt file.)
(I grab 2 Bytes at a time) Example Data --> hexValue[0]='7' and hexValue[1]='F'.
hexValue[0]=dataFile.read(); // Read 1st Hex Digit.
hexValue[1]=dataFile.read(); // Read 2nd Hex Digit.
Using code that works is one thing, but understanding it is another. I want to understand this below, but can't find any explanation online.
byte tens = (hexValue[0] < '9') ? hexValue[0] - '0' : hexValue[0] - '7'; (Why does this work? )
byte ones = (hexValue[1] < '9') ? hexValue[1] - '0' : hexValue[1] - '7'; (Why does this work? )
byte number = (16 * tens) + ones; (I understand this.)
I understand the last line, simple HEX math. But the 2 above that confuse me. It appears to be some kind of conditional statement, but It confuses me. Any feedback would be appreciated. Thanks.