MSD to LSD trying to change order

Hi, The code is a string, parsing an (enumeration list) enum which breaks down pieces of the code. When I do that it reads the least significant digit but I need to reverse them to read the Most significant first. The only way I know how to do this is to break it down and do the weights of the pieces. Any ideas or direction would be helpful. This is an example of the code.
Code in Particle Build

char input[] = "03D88039E8987A21489A376EF603000000C0060000CF060D3B00000000009C1B";//These are the strings coming into the radio 
char input1[] ="03D88039E8987A21489A376EF603000000C0060000CF060D3B00000000009C1B";
 
char parsedArray[14][13];
const int len[] = {2,12,2,2,4,6,6,4,4,4,6,6,2,4}; // the length of each of the pieces
int offset; // used to create offsets into the input string to the beginning of each piece
 
enum pieces {messageType,deviceID,deviceType,sequenceNumber,checkSum,wattHrR_L,wattHrsL_R,Voltage,Temp,Current,ampHrR_L,ampHrL_R,filler,CrC}; //to break up the sting into the different pieces there always a fixed length. 
 
void setup() {
   Serial.begin(115200);
    delay(3000);
    for(int t=0; t<2; t++){ //loop # times 
    for (int i=0; i<14; i++) {
        snprintf(parsedArray[i], len[i] + 1, "%s", input + offset); // len[i] + 1, the plus 1 is to allow space for the terminating zero
        offset += len[i];
    }
    delay(100);
 
    // Access the individual strings using the names in the enum
            Serial.println(input);
            String_break();
            
            Serial.println(input1);
           // Radio_calc();
            String_break();
}
}//end code
void String_break()
{
            Serial.printlnf("Message Type is: ",parsedArray[HEX,messageType]);
            Serial.printlnf("Device Id is: %s",parsedArray[deviceID]);
            Serial.printlnf("Device Type is: %s",parsedArray[deviceType]);
            Serial.printlnf("Squence #: %s",parsedArray[sequenceNumber]);
            Serial.printlnf("Check Sum is: %s",parsedArray[checkSum]);
            Serial.printlnf("Watt Hours R-L is: %s",parsedArray[wattHrR_L]);
            Serial.printlnf("Watt Hours L-R is: %s",parsedArray[wattHrsL_R]);
            Serial.printlnf("Voltage is: %s",parsedArray[Voltage]);
            Serial.printlnf("Temp is: %s",parsedArray[Temp]);
            Serial.printlnf("Current is: %s",parsedArray[Current]);
            Serial.printlnf("Amp Hrs R_L: %s",parsedArray[ampHrR_L]);
            Serial.printlnf("Amp Hrs L_R: %s",parsedArray[ampHrL_R]);
            Serial.printlnf("CRC code is: %S",parsedArray[CrC]);
}

This is the print out of Voltage

Voltage is: C006
Need is: 06C0

Any suggestions/insight on what’s happening and how to get to the most significant value?

Appreciate any help you can provide.

The parsing logic is all yours - just implement a swap for all these “back-to-front” parts of your string.

BTW, with a fixed format string, I’d use a struct which just overlays your raw string (union) this way you can access each individual substring direct (use of sizeof() for length of substring).

2 Likes