How to compare time-of-day numbers stored in Binary Coded Decimal in PIC
Binary-coded (BCD) decimal simply simply means each decimal digit is encoded in 4 bits (0-9, or 0000 to 1001), with the remaining six values (10-15, or 1010 to 1111) unused.  Usually two BCD digits are placed side by side inside an 8-bit byte, so values of 0-99 can be encoded.

So a minutes value of 59 would be encoded as:

0101 1001     0x05  0x09


instead of its binary representation:

0011 1011    0x3B    (3*16 + 11 = 59)


Encoding digits this way makes it easy to display them, since you only have to shift and mask them, no binary to decimal conversion is necessary.  E.g. if you have two BCD digits in a byte BCDdigits (which might represent one of the registers in the RTCC module), then 

ones = BCDdigits &amp; 0xf;
tens = BCDdigits &gt;&gt; 4;


These examples all assume unsigned variables. 

Two multi-digit numbers both in BCD format can be compared directly, as long as they are aligned correctly.  

For example, the registers in the PIC18 RTCC are all 8 bit.  So you have to either do this:

if ((HOURS == 0x10) &amp;&amp; (MINUTES == 0x20))


or this

if ((HOURS &lt;&lt; 8) | MINUTES ) == 0x1020)


where HOURS and MINUTES are the hours and minutes registers in the PIC18 RTCC.

If the second number to be compared is not in BCD, then you will need to convert them to a common base, such as minutes.  So if you have one byte containing minutes in BCD, and another containing hours in BCD, you could compute:

unsigned short minutes;
minutes = 600*(HOURS &gt;&gt; 4) + 60*(HOURS &amp; 0x0f)
         + 10*(MINUTES &gt;&gt; 4) + (MINUTES &amp; 0x0f);


and then compare that with your other value also converted to minutes.