How to cascade Hexadecimal no

char host1[]= {0xDD,0xA5,0x03,0x00,0xFF,0xFD,0x77};
//Desired output=0xDDA50300FFFD77

Output to what?

@deepakgautam, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Do you see [] in your on-liner? That's because you did not use so-called code tags; please read the section about posting code in How to get the best out of this forum and applyn it in future.

I want to cascade all the hexadecimal numbers in a variable from the array.

I'm sorry, I didn't realise that this was a game of Synonyms.

Where do you want to flood the data to?

Hello deepakgautam
Take some time and describe the desired function of the sketch in simple words and this very simple and short form.
Have a nice day and enjoy coding in C++ and feel free to reply for any help.
Дайте миру шанс!

Maybe something like this?

  unsigned char host1[] = {0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77};

  uint64_t x = 0;
  for (size_t i = 0; i < sizeof(host1); i++) {
    x = x << 8 | host1[i];
  }

  // x now contains 0xdda50300fffd77
1 Like

@jfjlaros

You codes generate expected output:

DDA50300FFFd77

Test Sketch

void setup()
{
  Serial.begin(115200);
  unsigned char host1[] = {0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77};

  uint64_t x = 0;
  for (size_t i = 0; i < sizeof(host1); i++) 
  {
    x = x << 8 | host1[i];
  }
  uint32_t *ptr;
  ptr = (uint32_t*)&x;
  uint32_t ml = *ptr;
  ptr++;
  uint32_t mh = *ptr;
  Serial.print(mh, HEX); //shows upper 32-bit DDA503
  if((ml & 0xFF000000) == 0)
  {
    Serial.print("00");
  }
  Serial.print(ml, HEX); //shows lower 32-bit as: 00FFFD77  
  // x now contains 0xdda50300fffd77 

}

void loop() 
{
  
}
1 Like

Thanks a lot. Its working.

The credit is for @jfjlaros. He wrote the codes for processing and I added codes to print the output.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.