Host Engineering Forum

General Category => General Discussion => Topic started by: PLCGuy on November 09, 2017, 10:39:00 AM

Title: Looking at bits
Post by: PLCGuy on November 09, 2017, 10:39:00 AM
I have a DWORD coming from a drive that shows the status of the outputs. Bit 0=Enable, Bit 1=Ready,.. and so on.
The binary may look like this 000_000_000_000_0111.  So I was thinking I want to look at bit 0 and if TRUE set C0. If bit 1 is TRUE then set C1,... etc. I was going to use a math box but confused how to use brackets and the such. How would one of you do it?
Title: Re: Looking at bits
Post by: franji1 on November 09, 2017, 10:42:25 AM
Are you simply doing a MOVE?  If so
MOVE SourceDWORD C0:SD

If you want to set/latch, then use MATH
MATH C0:SD "SourceDWORD | C0:SD"
Title: Re: Looking at bits
Post by: BobO on November 09, 2017, 10:43:27 AM
If the data were located in D0, you could use a simple bit cast like D0:n where n = bits 0-31. So read or write the third bit in D0, it is D0:2.
Title: Re: Looking at bits
Post by: PLCGuy on November 09, 2017, 12:09:45 PM
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)
Title: Re: Looking at bits
Post by: BobO on November 09, 2017, 12:28:27 PM
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)

MATH box works, but not needed. STR ormectrx:8 OUT C0 works fine, or a MOVE, INIT, or any other instruction that will do the assignment.
Title: Re: Looking at bits
Post by: BobO on November 09, 2017, 12:30:15 PM
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)

MATH box works, but not needed. STR ormectrx:8 OUT C0 works fine, or a MOVE, INIT, or any other instruction that will do the assignment.

And if you did a MATH box you don't need the IF(). Just MATH C0 ormectrx:6 works.
Title: Re: Looking at bits
Post by: franji1 on November 09, 2017, 12:37:59 PM
Are you simply doing a MOVE?  If so
MOVE SourceDWORD C0:SD

If you want to set/latch, then use MATH
MATH C0:SD "SourceDWORD | C0:SD"

or the new COPY instruction in lieu of MOVE
Title: Re: Looking at bits
Post by: PLCGuy on November 09, 2017, 02:16:43 PM
Ended up using Copy. I did not realize to treat the bits as STR.

Thanks, you both got me thinking.
Title: Re: Looking at bits
Post by: franji1 on November 09, 2017, 02:30:43 PM
Take 2

Since both the Source and the Destination are both contiguous, just set the Count to 6
Title: Re: Looking at bits
Post by: PLCGuy on November 10, 2017, 07:37:54 AM
Thanks that works great. I did not know I could write C0-C5 like that in the box.

I tried to show this stuff to a die hard AB guy and he just walked away, lol.