> > Does anybody have a routine for implementing bit reversal ? > > i.e. 11000000 to be converted to 00000011 > > This topic has just been discussed in the PIC16CXX forum on the > Microchip BBS (see messages 127246,127625 and 127775). Here is the > solution given by Mark Palmer of Microchip: > [17 instructions deleted] > > But then again this might be too obvious for the PICLIST ... But that version requires the old and new operands to be stored in seperate memory locations and takes 17 cycles. My version [tested on paper] takes only 16 and uses the same location for source and destination: rrf Num,w xorwf Num,w andlw $22 btfsc Num,0 xorlw $07 btfsc Num,3 xorlw $07 btfsc Num,4 xorlw $70 btfsc Num,7 xorlw $70 xorwf Num,f rrf Num,f xorwf Num,f rlf Num,f swapf Num,f If you are using a non-5x part and need to preserve carry, adding "addlw $80" after the first instruction will accomplish this. Does anyone see any way to make the code execute in less than 16 cycles? It took a lot of figuring to squeeze it below 17--am I missing anything?