I'm trying to build a program that calculates the difference, in seconds, between two times. I want to read the time from an I2C realtime clock and convert the time into a total in seconds. For example, for 11:18:58, I want to be able to do (11x3600) + (18x60) + (58) = 40738. However the reading I get back from the realtime clock are hex values and when I try to convert them to a decimal the values change accordingly, for example 11 changes to 17. This then messes up the calculations. Please see below:
printf("%02x:%02x:%02x", buf, buf, buf);
total = (buf)*3600;
printf("total = %d", total);
I've seen various bits of code for converting from a hex to a decimal but nothing that will allow me to use the raw hex value. Any suggestions greatly appreciated, thanks.