String to Hex

Hi,

I am working on a wireless IR Remote solution.

I am sending the IR HEX Code using wireless communication. That involves in my case converting the HEX value 0xFFFFFFFF to a string.

On the remove Arduino I need to convert the value back to a Unsigned Long value for it to be usable to the IRRemote library.

How can I do this. I have tried the following demonstration code, but it is not working.

 //IR CODE
  Serial.println("Sending Command");
  String strCode = "E13EF30C";

  Serial.print("Converting String: ");
  Serial.println(strCode);

  unsigned long tmpCode = strCode.toInt();

  Serial.print("Converted Code: ");
  Serial.println(tmpCode, HEX);

  irsend.sendNEC(tmpCode, 32);
  delay(1000); //5 second delay between each signal burst
  Serial.println("Sending Command");
  irsend.sendNEC(tmpCode, 32);
  delay(5000); //5 second delay between each signal burst

I hope someone can help me.

The String::toInt() method expects the String to contain a base 10 representation of the number, not a base 16 representation.

Why are you converting the value to a base 16 representation? Send a base 10 representation, and use toInt().

Or, quit using Strings, and use strtoul() to convert the string to a number.

Thank you for your reply.

I have only been able to get it working using a hex code.

So if I convert it to int, then send it over, how do I convert it back to hex?

Ok, it seems you are right. If I convert it to unsigned long, then it still works, and I should be able to send that over the air.

Thank you, I seems to have what I need for now...

  //IR CODE
  unsigned long hexCode = (0xE13EF30C);
  
  Serial.print("Input: ");
  Serial.println(hexCode, HEX);

  unsigned long intCode = (hexCode);
  

  Serial.print("intCode: ");
  Serial.println(intCode);

  irsend.sendNEC(intCode, 32);
  delay(1000); //5 second delay between each signal burst
  Serial.println("Sending Command");
  irsend.sendNEC(intCode, 32);
  delay(5000); //5 second delay between each signal burst