The piece of code that Tracy posted (from John Payson) does what it was originally meant to do BUT is NOT correct for the present problem. Here we require 76543210 --> 01234567 John's solution is for a 7 bit swap ignoring B7. ie x6543210 --> x0123456 As a consequence B7 & B3 is untouched and there are only 3 swaps needed making the code shorter. Rewriting it for an 8 bit swap as required here, produces - movwf source btfsc source,0 xorlw h'81' btfsc source,7 xorlw h'81' btfsc source,1 xorlw h'42' btfsc source,6 xorlw h'42' btfsc source,2 xorlw h'24' btfsc source,5 xorlw h'24' btfsc source,3 xorlw h'18' btfsc source,4 xorlw h'18' 17 instructions, time varies depending on data but fairly quick. Operation may not be initially obvious. It implements For N = 0 to 3 If bN = 1 then invert bits bN and b(7-N) If b(7-N) = 1 then invert bits bN and b(7-N) Next N Worst case, if both bits in a pair are set it inverts them both twice. Best case, if neither is set it takes no action. This suggests that a more cunning test for "both bits set" may allow a small reduction in run time but intuition suggests that the testing overhead would be excessive.. John's solution is elegant but a little hard on the brain. I prefer Dwayne Reids more brute force - > clrf dest > btfsc source,0 > bsf dest,7 > btfsc source,1 > bsf dest,6 > btfsc source,2 > bsf dest,5 > btfsc source,3 > bsf dest,4 > btfsc source,4 > bsf dest,3 > btfsc source,5 > bsf dest,2 > btfsc source,6 > bsf dest,1 > btfsc source,7 > bsf dest,0 because it's much easier for trhe average person to see what is happening at a glance (or a few glances :-) - YMMV). A full 8 bit lookup table is much quicker and much much less code space efficient. A dual nibble lookup table is not much quicker on average and rather less code efficient. Lookup tables have the possible advantage of having a constant implementation time. Russell McMahon _____________________________ >From another world - www.easttimor.com What can one man* do? Help the hungry at no cost to yourself! at http://www.thehungersite.com/ (* - or woman, child or internet enabled intelligent entity :-)) From: Tracy Smith >>I want to change b7 b6 b5 b4 b3 b2 b1 b0 to b0 >b1 b2 b3 b4 b5 b6 b7. >> >>Quickest & most code efficient?? > >How about this... (John Payson) > > movwf source > btfsc source,0 > xorlw h'41' > btfsc source,6 > xorlw h'41' > btfsc source,1 > xorlw h'22' > btfsc source,5 > xorlw h'22' > btfsc source,2 > xorlw h'14' > btfsc source,4 > xorlw h'14'