On Tue, Mar 06, 2007 at 12:18:39PM -0600, PAUL James wrote: > > Sir, > > I would "AND" the number '54' with 0x0F. This will give you '4'. Store > it in it's destination register, whatever tht may be. That's only if the number is 54 hex. 54 decimal is 36 hex. So anding with 0x0F would actually give you a 6. You'd need to convert hex to BCD, then perform the operation in question. > Then do a SWPAF > and "AND" it again with 0x0F. This will give you the '5'. Store it > In it's destination register. Now you're done. Same problem as before. For my sunrise/sunset outdoor light controller I wrote a hex to BCD routine. It's a bit involved. The basic idea was to convert the high nex nybble to BCD via a table, then add the low BCD digit. For example your 54 decimal (0x36) would take the 0x30 and convert it to 0x48, which is the BCD equivalent to 0x30. It then adds the 6 back giving 0x4E. You then decimal adjust by adding 6 more giving 0x54, which is the BCD equivalent to the original 0x36. Here are my comments from the routine which can be found here: http://www.finitesite.com/d3jsys/clock.asm ; Add the low nybbles together. Compensate if the sum is greater than 9 ; Then add the result to the high nybble of the BCD of the high nybble. ; The low digit add plus the compensation may have pushed the low digit back ; into the hex range. Need to check and recompensate. For example 1F maps to ; (16 + 0F). The low digit sum is 15 hex and with the compensation is bumped ; to 1B. It needs to be compensated again by adding 6 more to get to 21 BCD. ; ... ; This is where recompensate the low digit sum if necessary. Note that ; This one only checks the low digit of the sum since presumably there will ; be some high digit carry when adding 8+9+6 for example. The simplest way is to do the repeated subtraction as suggested in another post. My conversion does simplify tracking the high BCD digit, but the low digit recompensation is a bit of a pain. BAJ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist