0

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,

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
user839917
  • 851
  • 5
  • 13
  • 20
  • What have you tried ? Did you tried to just [reverse hex string](http://stackoverflow.com/questions/784417/reversing-a-string-in-c) ? – Agnius Vasiliauskas May 30 '12 at 06:24
  • yes thats what i want to do. reverse the hex string. Currently the hex string stores the serial number of certificate. and i want to reverse this serial number as in the example i gave earlier – user839917 May 30 '12 at 06:26

1 Answers1

1

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.
stefaanv
  • 14,072
  • 2
  • 31
  • 53