> anyone have a routine for reversing the order of bits in a byte? Josh, dug these out of a far corner of the HDD. I tried them at the time to get around the same problem as you've got ============================================ From: Dwayne Reid To: Subject: Re: Efficient way to reverse a byte? Date: Saturday, 30 October 1999 06:51 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 17 instructions, 17 cycles ========================================= From: Terry A. Steen Date: Saturday, 30 October 1999 07:22 How about: rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in rlf arg1,1 ;shift out a bit rrf arg2,1 ;shift it in Kind of long, but this should reverge arg1 and store it in arg2. At the same time, it will also reverse arg2 and store it in arg1 ============================================= From: Russell McMahon Date: Saturday, 30 October 1999 11:53 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 -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics