I hope I don't make a complete fool of myself, but here is my try: From the example I understood that it is OK to trash INDF. I interpreted 'including return' as including the 2 cycles for the return. decf INDF, w bsf INDF, 7 andwf INDF, w return the formula is ( x - 1 ) & ( x | 0x80 ) explanation: (x-1) leaves all set bits in place, except the rightmost one, which is 'smeared out' over the lower bits. Hence (x-1)&(x) is 0 when there was only one bit set, OR x was 0. From x==0 follows (x-1) == 0xFF, and (x-1) & (anything<>0) != 0. When only one bit is set the highest bit in (x-1) will be clear, so it has no effect (except in the all clear case, wher it has the desired effect) to use (x|0x80). verification: #include int f( int x ){ return ( 0xFF & ( (x - 1) & ( x | 0x80 ) ) ); } int ones( int x ){ int n = 0; while( x > 0 ){ if( x & 1 > 0 ){ n++; } x = x >> 1; } return n; } int main( void ){ int i, j, k; for( i = 0; i < 256; i ++ ){ j = f( i ); k = ones( i ); printf( "%2X %2X %2X %d\n", i, j, k, ( k == 1 ) == ( j == 0 ) ); } return 0; } -- http://www.piclist.com hint: PICList Posts must start with ONE topic: "[PIC]:","[SX]:","[AVR]:" =uP ONLY! "[EE]:","[OT]:" =Other "[BUY]:","[AD]:" =Ads