From: Mike Keitz. There is a trick method that works for 4 bits. It replaces a 2-bit number in a variable with a 4-bit mask:
incf BitP, W ;W = 0001 0010 0011 0100 btfsc BitP, 1 ;If 0 or 1, result is almost correct now. iorwf BitP, F ;BitP =   0011 0111 incf BitP, F ;BitP = 0001 0010 0100 1000
Bob Ammerman gave me this one. I used it to convert a device number to a pin bit number. I call it "bobbit" ;-)movf portb,w andlw b'00000011' movwf temp1 movlw .1 btfsc temp1,1 movlw .4 btfsc temp1,0 addwf wreg,w btfsc temp1,2 swapf wreg,w movwf temp2 portb = xxxxxx00, temp2 = 00000001 portb = xxxxxx01, temp2 = 00000010 portb = xxxxxx10, temp2 = 00000100 portb = xxxxxx11, temp2 = 00001000
Russell McMahon says:
Here's a lateral thought :-).
If you can decide which of the 4 output lines is output 1,2,3,4 (as will usually be the case) you can solve this as follows Assumes bits are in LSBs and no other bits set. AND high bits if required.
Input in W in each caseAdd 1 to W If result = 3 then result = 8
OrIf W = 2 then W = 7 Add 1 to W
|file: /Techref/microchip/math/bit/2to4mask.htm, 1KB, , updated: 2004/12/16 16:18, local time: 2020/11/29 02:11,
|©2020 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.sxlist.com/techref/microchip/math/bit/2to4mask.htm"> Converting a 2-bit number to a 4-bit mask</A>
|Did you find what you needed?|
Welcome to sxlist.com!
& kind contributors
just like you!
Please don't rip/copy
Copies of the site on CD
are available at minimal cost.
Welcome to www.sxlist.com!