# IRsend problem!!

my question is : I’ve to send an IR pulse and i don’t want to add the code manually every time i change my device so, the code is this :

unsigned long int Val;
int B;

if(reciver.decode(&results)){
String C = “0x” + String(results.value, HEX);
C.toUpperCase();
constant char* Pass = C.c_str();
Val= strtoul(Pass, NULL, 16);
B = results.bits, DEC;
delay(1000);
}

for(int i = 0; i< 3; i++){
irsend.sendNEC((Val, HEX) , B);
delay(100);
}

Where is my problem?? My problem is that after conversion of Val into unsigned long value I have only the value without the 0x initial.

So for example if i have 0x123ABC2E if i put manually into the for cycle it works but after conversion the variable Val have only 123ABC2E and if i put it into the for cycle it doesn’t works!

So I know that the 0x initial is only for determinate the base of the value but i need to add it can anyone help me to add this code into the value or into the irsend funch?

I hope to have explained well the situation!

Thanks at all for the attention!

DavideTibe: . . . if(reciver.decode(&results)){ . . . Where is my problem?? . . .

You've spelled receiver incorrectly ?

No man haha i've Made a mistake but that is not the problem!

I need to add the 0x in front my value!

So for example :

I've an unsigned long int variable called A and his value is 234DAF2E.

My intent is to add the 0x in front the A variable value so it will be like this 0x234DAF2E!

I don't know how can I do it but I need to do!

You seem confused. The base is only relevant in the string representation, the value in an integer variable is just an integer (you don't care about the base unless doing bit operations for which the base is 2).

To convert a hexadecimal string without an "0x" to an integer use

``````unsigned long value = strtoul ("abcdef", 0, 16);
``````

To convert an integer to a hex string with a '0x' use:

``````Serial.print ("0x") ; Serial.print (value, HEX) ;
``````

I'm still unclear what you are trying to do.

Ok man I know what u mean but! What I want to do is to change a tv channel with arduino but... If I use the code keeping the initial 0x I'm able to do it and without the 0x I'm not able to do the same! I don't know how can I add the 0x initial!!

`````` B = results.bits, DEC;
``````

What do you think this is doing? It isn't...

DavideTibe: Ok man I know what u mean but! What I want to do is to change a tv channel with arduino but... If I use the code keeping the initial 0x I'm able to do it and without the 0x I'm not able to do the same! I don't know how can I add the 0x initial!!

So you are getting a hex string from somewhere and need to convert to an unsigned long? I told you this already, use strtoul()