Dudes: John Payson accidentally sent the following message to me directly; I'm forwarding it to the PICLIST. -Andy ------- Forwarded Message Follows ------- From: John Payson Subject: Re: Bit Number to Bit Mask Question To: fastfwd@ix.netcom.com Date: Wed, 17 Sep 1997 16:39:38 -0500 (CDT) > > Using a PIC, has anybody figured out a good way to take a number > > from zero to seven (0 to 7) and use it to generate the > > corresponding bit mask (i.e., 00000001, 00000010, 00000100, etc.)? > > Frank: > > Every time I'm faced with this problem, I spend a few minutes trying > to find a method that's better than a lookup table... So far, I > haven't found one. Hmm... movlw $01 btfsc BITNUM,1 movlw $04 movwf temp bcf C btfsc BITNUM,0 rlf temp movf temp,w btfsc BITNUM,2 swapf temp,w Not terribly encouraging (10 words/10 cycles). Maybe... movlw $FF btfsc BITNUM,0 andlw $AA btfsc BITNUM,1 andlw $CC btfsc BITNUM,2 andlw $F0 movwf temp comf temp incf temp andwf temp,w Interesting, but even worse (unless I'm missing an optimization on that ending part). Anyone see any improvements for those two methods above? ------- End of Forwarded Message ------