dec = (bcd >> 4) * 10 + (bcd & 15)
But how can I convert decimal back to BCD?
I'm using a DS3231 (real time clock) and need to send the time and date in BCD to set the clock.
For instance the seconds are the four LSB from a byte, and the tenths of the seconds are bit 4/5/6 from the byte (bit 7 is not used in the range 0-59).
So if I want to set the seconds, how can I convert the decimal value to a BCD value?