I've never done it before, but I'd use a lookup table. Just make sure you don't run off the end of the table. movlw d'7' subwf number,w ;compare numbers SKPNC ;if number is larger than 7 goto ValueOutOfBounds ;do this! movlw number ;else this. call GetBitMask ;the correct bit mask will be in w now. ;rest of program. ValueOutOfBounds error codehere. GetBitMask addwf PC,f retlw b'00000000' retlw b'00000001' retlw b'00000010' retlw b'00000100' retlw b'00001000' retlw b'00010000' retlw b'00100000' retlw b'01000000' retlw b'10000000' -Shane. On Wed, 17 Sep 1997, Frank Dalton wrote: > 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.)? > > This is bound to be an old problem solved long > ago by gurus more wiser than me. Who has the > best code snipet for doing this operation? > > -- > ------------------------------------------------------ > /\ Frank Dalton (fdalton@pineinst.com) > //\\ Pine Instrument Company > ///\\\ 101 Industrial Drive > ////\\\\ Grove City, PA 16127 > || (412) 458-6391 > || www.pineinst.com > ------------------------------------------------------ >