How i convert char array to HEX

I am using im920 radio module, this device transmits all data as HEX, So now I put all received data in the array. Now i am unable to convert to those character into HEX.
array 'data_value[1]' & array 'data_value[2]' have the temperature and Humdity value.

Below i am sharing my code, i will be very Grateful if someone helps me here:

void loop() {
  // put your main code here, to run repeatedly:
    delay(1000);
    if (im920serial.available()){
      count=0;
      count2=0;
      while (im920serial.available()){
        dummy=im920serial.read();
        if (dummy!=',' && dummy!=':') {
          data_value[count2][count]=dummy;
          count++;
        }      
        if (dummy==':') {
          count=0;
          count2++;
        }
        if (count2>0 && count>3) {
          count=0;
          count2++;
        }      
        
      }

    }
      Serial.println(data_value[1]);// this the array value for Temp; How i convert this value?
    //Serial.println(data_value[0]);
    //Serial.println(data_value[1]);
    //Serial.println(data_value[2]);// this the array value for Humd; How i convert this value?
    
    if (Serial.available())
    im920serial.write(Serial.read());
    
}

If I understand correctly the array contains 2 rows of data, each of 4 characters

Try

for (int row = 0; row < 2; row++)
{
  for (int col = 0; col < 4; col++)
  {
    Serial.print(data_value[row][col]);
  }
}

EDIT : see corrected version in reply #3

Dear UKHeliBob,
Thanks for your replay, i don’t properly understand what you are saying.
i am sharing the serial output in the attachment.

Where did that output come from ?

Corrected version of my code from reply #1

  for (int row = 0; row < 2; row++)
  {
    for (int col = 0; col < 3; col++)
    {
      Serial.print(anArray[row][col]);
    }
    Serial.println();
  }

Output comes from the Array.

Until now unable to understand; how i use your code?
how this code converts my char array value into HEX??

Sorry for my poor understanding...

Until now unable to understand; how i use your code?

Run it after collecting the data in the array

how this code converts my char array value into HEX??

It prints the contents of the array, it does not convert it

When you say that you want to convert the array value into HEX what do you mean ?
Do you mean that if a row of the array contains '0' '9' 'C' '4' you want to put it into a variable and give it the value of 0x09C4 or something else ?

array ‘data_value[1]’ & array ‘data_value[2]’ have the temperature and Humidity value.

Does it mean:

1. The following array elements contain Temperature Data

data_value[1][0]
data_value[1][1]
-------------------
data_value[1][9]        //you have 10x10 character array;

Each array element contains 1-byte ASCII code for a HEX-digit; now, you combine two elements to get 1-byte HEX number. You have 10 elements (array members); after processing, you will get 5-byte data for the Temperature value. How to interpret this 40-bit data to find Temperature value in decimal format, that you know.

2. The following array elements contain Humidity Data

data_value[2][0]
data_value[2][1]
-------------------
data_value[2][9]        //you have 10x10 character array;

Serial.println(data_value[1]);// this the array value for Temp; How i convert this value?

Do you know the meaning of the above instruction - what will it print? It is going to print the contents of the following array elements one after another.

data_valuw[1][0], ...., data_value[1][9]    //Temperature value in character format 
data_value[2][0], ...., data_value[2][9]    //Humidity value in character format


data_value[9][0], …, data_value[9][9] //----

Now, create your array manually:

char data_value[10][10] =    {

{'x', 'x', ................, 'x'},              //data_value[0][0], ............, data_value[0][9]
{'x', 'x', ................, 'x'},              //data_value[1][0],............., data_value[1][9]  //Tempertaure
{'x', 'x', ................, 'x'},              //data_value[2][0],............., data_value[2][9]  //Humidity 
..................................                .......................................................................................
{'x', 'x', ................, 'x'}               //data_value[9][0],............., data_value[9][9]

};

Assume that:

data_value[1][0] = 0x31      //1     assume lower digit of the HEX byte
data_value[1][1] = 0x45      //E     assume upper digit of the HEX byte

How to extract E1 from the above two elements?

byte x = data_value[1][0];    // x = 0x31 = 30 + 01
if (x < 0x41)
{
  x = x - 0x30;      // x = 0x31 - 0x30 = 0x01 = 00000001
}

else
{
  x = x - 0x37              //
}

byte y = data_value[1][1];    // y = 0x45 
if (y < 0x41)
{
  y = y - 0x30;      //
  y = y << 4;         //
}

else
{
  y = y - 0x37;              //0x45 - 0x37 = 0x0E = 00001110
  y =  y << 4;              //y = 11100000          
}

x = x|y;                     //x = 00000001 | 11100000 = 11100001 = E1

Now, you can use for() looping construct to reduce the number of instructions.

Do you mean that if a row of the array contains '0' '9' 'C' '4' you want to put it into a variable and give it the value of 0x09C4 or something else ?

No answer yet to my question, but if I am right, then of you put '\0' in column 4 of each row of the array you can use strtol() to convert the string to a long and use it how you like

Example

char anArray[2][10] = {'0', '9', 'C', '4', '\0'};
long aLong;

void setup()
{
  Serial.begin(115200);
  Serial.print("array : \t");
  Serial.println(anArray[0]);
  aLong = strtol(anArray[0], NULL, 16);
  Serial.print("decimal : \t");
  Serial.println(aLong, DEC);
  Serial.print("HEX : \t\t");
  Serial.println(aLong, HEX);
  Serial.print("binary : \t");
  Serial.println(aLong, BIN);
}

void loop()
{
}

Dear UKHeliBob,
Thank you so much ;D ;D It's working...

nayeenalamin:
Dear UKHeliBob,
Thank you so much ;D ;D It's working...

Good to hear, but I hope that you realise that what my code did was to convert the string in the array to a long and display it several ways, one of which was HEX. The actual value is in the variable. How you display it is up to you.

Dear UKHeliBob,
I am trying to serial print like below:

        Serial.print("Humd_HEX : \t\t");
        Serial.println(Humd, HEX);
        Serial.print("Humid_decimal : \t");
        Serial.println(float(Humd)/float(x), DEC);

And i am getting output like this:

Temp_HEX : 94A
Temp_decimal : 23.7800006866
Humd_HEX : 1A83
Humid_decimal : 67.8700027465

How i make the Decimal value like 23.78 and 67.87

Advance thanks

You have difficulty converting 2378 to 23.78 and 6787 to 67.87?

Try this:

Serial.print(Temp_HEX/100.0, 2);//

If you get what you want after the execution of the above instruction, then answer to the following question without doing any experiment with the Arduino.

What value would you see on the Serial Monitor if you execute the following instruction?

Serial.print(Temp_HEX/100, 2);

GolamMostafa:
What value would you see on the Serial Monitor if you execute the following instruction?
Serial.print(Temp_HEX/100, 2);

Why would you want to print in binary? :o