I'm reading data from UART byte by byte. This is saved to a char. The byte following the start byte gives the number of subsequents bytes incoming (as a hexadecimal). I need to convert this hex number to an integer, to keep count of bytes required to be read.
Presently I'm simply type-casting to int. Here's my code:
char ch;
int bytes_to_read;
while(1){
serial_read(UART_RX, &ch, sizeof(char));
if(/*2nd byte*/){
bytes_to_read = (int)ch;
}
}
I read about strtol(), but it takes char arrays as input. What's the right way to do this?
charto anint- so what's the actual problem ? - Paul R0x03really as 4 characters0,x,0and3or as one byte with the representation0x03and the value 3? Be sure you are clear about the distinction of value and representation. - glglgl