This problem came up on plcs.net.
The times cited for reversing bits seemed a little long so I wrote an example of how to reverse bits on the RMC70/RMC150 just for comparison.
I have an updated version down below.
Thats almost to easy Peter.
I have a somewhat related question. I think you have a good way of dealing with bits and dwords. I don’t see anything about working with bytes or words. Can you move 4 bits at a time from one variable to another?
myVar1.0..3 = myVar2.0..3
I know you can do it this way[code]
myVar1.0 := myVar2.0
myVar1.1 := myVar2.1
myVar1.2 := myVar2.2
myVar1.3 := myVar2.3
Now that the RMC has user functions I am taking advantage of them.
Just copy and paste.
This function takes 7.3 microseconds to execute.
FUNCTION REVERSE_BITS : DWORD
Bits:=(SHR(Bits,1 ) AND 16#55555555 ) OR SHL(Bits AND 16#5555555,1 );
Bits:=(SHR(Bits,2) AND 16#33333333) OR SHL(Bits AND 16#33333333,2);
Bits:=(SHR(Bits,4) AND 16#0F0F0F0F) OR SHL(Bits AND 16#0F0F0F0F,4);
Bits:=(SHR(Bits,8) AND 16#00FF00FF) OR SHL(Bits AND 16#00FF00FF,8);
REVERSE_BITS:=SHR(Bits,16) OR SHL(Bits,16);