HEX String to unsigned long

I need to send hex string by IR but at firs i need to combine it from 3 variables. So i use string function to merge HEX (1+A+C= 1AC) but problem is that i can’t to send string -----> irsend.sendSony(string, 12); IRSend library need to send unsigned long or int. So then i need to convert string to unsigned long code but i don’t know how :frowning:

#include <IRremote.h>

IRsend irsend;

 String stringOne;
 String stringTwo;
 String stringThree;
 String string;

unsigned long code;

void setup()

void loop() {
  int Team = 1;     //in HEX = 1
  int Player = 10;  //in HEX = A
  int Weapon = 12;  //in HEX = C
  stringOne =  String(Team, HEX);     //HEX = 1
  stringTwo =  String(Player, HEX);   //HEX = A
  stringThree =  String(Weapon, HEX); //HEX = C
  string =  String(stringOne + stringTwo + stringThree); //1 + A + C = 1AC
  Serial.println(string); // i get 1AC
  //need convert it like this to send it, but i can't 
  code = string; //????????????
  //Because "irsend.sendSony" accept just (unsigned long or int) i can't send string directly   
  irsend.sendSony(code, 12); // need to send it like this irsend.sendSony(0x1AC, 12); 

Hex is just a convenient way of presenting binary to humans, but hex, decimal, octal or binary, it's all the same value to the processor.

ok, now i understand about HEX, OCTAL, DEC ... but how i can string convert to unsigned long to make IR library understand that i wand send 0x1AC code?

Tell me why you made a String (note, that's not the same as a string) when all you want to do is transmit a binary value.

i just want 3 different hex values stick together and send as one code and in receiver i was split them again and asign to variables

variable1 = 1; //hex 1
variable2 = 10; //hex A
variable3 = 12; //hex C

i want stick them together and send as



receive = 1AC

split this received code and asign to variable:
variable1 = 1; // hex 1
variable2 = 10; // hex A
variable3 = 12; // hex C

Hello :slight_smile:

Try something liek that:

int Team = 1;     //in HEX = 1
int Player = 10;  //in HEX = A
int Weapon = 12;  //in HEX = C

irsend.sendSony( Team << 8 | Player << 4 | Weapon , 12);

Are you saying you want to send the ASCII string "0x1ac"? Or the value 0x1ac?

Perfect!!! Thank you "guix" !! That is that what i want! Looks so easy but i never would do this without your help!

NP 8)

And if you are wondering how to "decode", here is a little example: http://codepad.org/kCuH0UVW