user839917
user839917

Reputation: 861

Byte order conversion in cpp

I am trying to solve a problem. I have a char * SERIAL_HEX = 5F6D1F7F But my code is expecting the SERIAL_HEX in reverse order. Like SERIAL_HEX = 7F1F6D5F

So its reversing the hex digits..How can i achieve this in c++ ? Any pointers will help me! Thanks,

Upvotes: 0

Views: 539

Answers (1)

stefaanv
stefaanv

Reputation: 14392

You have (at least) 2 possibilities:

  • convert each character pair to a byte, reverse the resulting string with std::reverse() and convert each byte back to its hex-representation
  • swap each character pair with the one counting from the end.

Upvotes: 1

Related Questions