0
votes

I'm trying to convert a hex decimal string value to an unsigned long int.

For example:

String s="0x4d14" --> unsigned long int B = 0x4D14


OK, I solved the previous problem,

I have another problem:

I read hexcodes from the serial monitor like this:

 char c[10];    
 char c[i]=serial.read();
 String s=c[i];
 i++;
 if (i==10)
     s="";

But now I can't do this:

   const char* string = s;

To use the strtoul function, so what should I do?

Whatever logic of my code, I didn't post my full code, but my problem now is string to const char* conversion.

1
long int A[]={0,x,1,2,3} cannot be right as x is no int?! - j.holetzeck
i'm reading hexadecimal values from the serial port and i want to convert it to unsigned long int. for example unsigned long int a[i]=serial.read(); where this incoming value was supposed to be hexadecimal - Youssef Fotouh
@j.holetzeck i have edited my question....do you know the answer? - Youssef Fotouh
@j.holetzeck this doesn't work for hex values - Youssef Fotouh

1 Answers

2
votes

This works for me

const char* string = "0x4d14";
long unsigned int b = strtoul(string, 0, 16);

Update:

char c[10];
... // read values
strtoul(c, 0, 16);
...

Have a look at some C language tutorial