Posted 7 Dec 2015 (edited) How to take single bit form input WORD by Structured Text? Can i write somethink like: inVar[i] Edited 7 Dec 2015 by Kaczi Share this post Link to post Share on other sites
Posted 12 Dec 2015 Yes you can. You need to declare the inVar as an Array of BOOL. That way you can access each bit independently using the syntax you write above, but the problem is you cannot access inVar as a Word You can, however, do a bitwise AND to check the certain bit condition of a Word Variable. Say you declare inVar as a single WORD (not an Array), you can use this kind of script to check : IF (InVar AND 1) > 0 THEN (*Check whether Bit 00 of InVar is ON*) (*Do something*) ELSIF (InVar AND 2) > 0 THEN (*Check whether Bit 01 of InVar is ON*) (*Do other thing*) ELSE (*Do other thing*) END_IF Share this post Link to post Share on other sites
Posted 12 Dec 2015 Assuming InVar is your word, you should be able to use dot notation to get to any individual bit in the word. The 2nd bit is at InVar.2 10th bit is at InVar.10 and so on.... Share this post Link to post Share on other sites
Posted 13 Dec 2015 Hello, unfortunately you cannot do that in CX-Programmer, either in Ladder Editor or Structured Text. Share this post Link to post Share on other sites
Posted 14 Dec 2015 in that case use AND operation with suitable bit mask... something like bitTestValue = (inVar AND Mask)>0 where Mask is same size as inVar but it only has one bit set, for example: bit 0: Mask= 1 bit 1: Mask= 2 bit 2: Mask= 4 bit 3: Mask= 8 bit 4: Mask= 16 etc Share this post Link to post Share on other sites