Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • It should be char HexString[3];, you need space for the null terminator at the end of the string. And depending on the source of the data input it may make sense to either use snprintf or verify that the value is never outside the expected range. It pays to always be paranoid about buffer overflows. Commented Aug 1, 2017 at 16:34
  • I usually have to think about these, but running a quick test in gcc confirms for a value of 0x05, HexString[0]='0', HexString[1]='5',HexString[2]=0. Commented Aug 2, 2017 at 0:41
  • Exactly, an array that is 3 long not the 2 long that you are allocating. Commented Aug 2, 2017 at 9:06
  • yes. you're right... edited :) Commented Aug 2, 2017 at 11:44
  • thank you very much for the quick respond.. I tried using the Second solution but I have a different issue now. I am actually trying to sent the HexString + another String like this mySerial.println("GR+" + HexString); and I get an error regarding char and string cannot be added together. Commented Aug 3, 2017 at 6:18