Searching \ for 'Bit Manipulaion' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=bit+manipulaion
Search entire site for: 'Bit Manipulaion'.

Truncated match.
PICList Thread
'Bit Manipulaion'
1997\12\31@062033 by Philip Martin

flavicon
picon face
Hi all,

I have a question about bit manipulation.

What I have is an input that reads '11010000' say. What I need to do is
convert it to '00001101' say.

One route seems to be to RRNCF four times. Would this do the job and not
affect any other registers?

Is there a better way to bit mask to create the desired result?

TIA,
& Happy New Year to all  on the list:-))



--
Philip Martin   email spam_OUTphilipTakeThisOuTspamphilmart.demon.co.uk

Royal Quays, North Shields.

1997\12\31@075550 by XYGAX

picon face
In a message dated 31/12/97  11:21:25, you write:

<<
What I have is an input that reads '11010000' say. What I need to do is
convert it to '00001101' say.

One route seems to be to RRNCF four times. Would this do the job and not
affect any other registers?
 >>
Philip thats ok if you are using 17cxx devices but the instruction dosent
exist on 12,16cxxx devices consequently first preserve carry if required then
rrf four times will get to the same place

somthing like
RRF     ANYREG,F
RRF     ANYREG,F
RRF     ANYREG,F
RRF     ANYREG,F
CLRC                         ; CLEAR GARBAGE FROM CARRY
BTFSC ANYREG,4      ; CHECK SEE WHAT CARRY WAS
SETC                         ; RESTORE IF REQUIRED.

Sounds like it should work u dont need to save carry during manipulation as it
is used but appears in bit 4 however the upperbits are not in the corect place
but this is only important if they are needed.

Sorry all the above is bollox

SWAPF   ANYREG,F    ; does exactly what you want in a single instruction
without affeactin any status bits.............

Cheers Steve

1997\12\31@090218 by Dmitry Kiryashov

flavicon
face
Hello Philip. Wish you Happy New Year too ! :-)

> I have a question about bit manipulation.
> What I have is an input that reads '11010000' say. What I need to do is
> convert it to '00001101' say.
>
> One route seems to be to RRNCF four times. Would this do the job and not
> affect any other registers?
>
> Is there a better way to bit mask to create the desired result?

As i understand you want to move bits in following sequence:
bit_7 => bit_3
bit_6 => bit_2
bit_5 => bit_1
bit_4 => bit_0

This is may be done by executing SWAPF FILE,F

Another variant is to using RRF FILE,F or RLF FILE,F commands series:
Due to PIC16Cxx have no RRNCF instruction you should apply additional
command before (see example)

       RRF     FILE,W ;copy FILE.0 to Carry
       RRF     FILE,F
       RRF     FILE,F
; do it as many times as you need

There are also another trick was described by John Payson some times ago
(i admire him ability to find non-standart solution :-)

To swap 7<->0 6<->1 5<->2 4<->3 do the following sequence:

       MOVFW   FILE
       BTFSC   FILE,7
       XORLW   0b10000001
       BTFSC   FILE,0
       XORLW   0b10000001
       BTFSC   FILE,6
       XORLW   0b01000010
       BTFSC   FILE,1
       XORLW   0b01000010
       BTFSC   FILE,5
       XORLW   0b00100100
       BTFSC   FILE,2
       XORLW   0b00100100
       BTFSC   FILE,4
       XORLW   0b00011000
       BTFSC   FILE,3
       XORLW   0b00011000
       MOVWF   FILE


WBR Dmitry.

1997\12\31@203706 by snsscj1

picon face
Philip -

I would think that the SWAPF instruction would work nicely if your
example of a four bit shift is representative.  Adding an XORFW with a
mask of 0xF0 will get rid of the high order bits if their not needed.

Steve

Philip Martin wrote:
>
> What I have is an input that reads '11010000' say. What I need to do
> is convert it to '00001101' say.
>
> One route seems to be to RRNCF four times. Would this do the job and
> not affect any other registers?

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...