This is actually part of a project I’m working on using an avr. I’m interfacing via twi with a DS1307 real-time clock IC. It reports information back as a series of 8 chars. It returns in the format:
// Second : ds1307[0]
// Minute : ds1307[1]
// Hour : ds1307[2]
// Day : ds1307[3]
// Date : ds1307[4]
// Month : ds1307[5]
// Year : ds1307[6]
What I would like to do is take each part of the time and read it bit by bit. I can’t think of a way to do this. Basically lighting up an led if the bit is a 1, but not if it’s a 0.
I’d imagine that there is a rather simple way to do it by bitshifting, but I can’t put my finger on the logic to do it.
Checking whether the bit N is set can be done with a simple expression like:
where bitmap is the integer value (e.g. 64 bit in your case) containing the bits.
Finding the seconds:
Finding the minute:
Finding the hour: