Back to tutorials
PLC Instructions

PLC Programming Comparison Instructions – MEQ | Masked Equal

Vladimir Romanov
Table of Contents


The MEQ, also known as the Masked Equals, is an instruction which will perform a similar function to the EQU (Equals) Instruction, with one key difference: a mask is applied to the compared bits. This instruction will take three operands: two which will be compared and a mask which needs to be applied. A mask is a key element of programming which boils down to selecting which bits need to be processed by the controller. In the case of the MEQ instruction, only the bits which have been masked as HIGH will be compared. Should those bits be the same within the two other operands, the instruction will evaluate to TRUE.

Although a masked comparison is not something you see on a regular basis in production ready code, it’s a great tool for certain situation. However, it must be used carefully as it is confusing to troubleshoot what’s going on unless you are familiar with this type of code. Use the MEQ instruction with caution.

Example & Usage of MEQ

Here’s a real-world scenario of a MEQ instruction:

  1. A Micrologix 1100 Allen Bradley PLC is used to control a process.
  2. In rung 0000, a MEQ  instruction is used to compare an Integer N7:0 to N7:2. A mask stored in register N7:1 is applied to the operation.
  3. The mask N7:1 is set to 0. In other words, 0000,0000,0000,0000 in binary.
  4. Since not a single bit of the mask was set to HIGH, the instruction will always evaluate to TRUE.
  5. The MEQ evaluates N7:0 compared to N7:2 to TRUE because of the specified mask.
  6. In rung 0001, a MEQ  instruction is used to compare an Integer N7:3 to N7:5. A mask stored in register N7:4 is applied to the operation.
  7. The mask N7:1 is set to 007Fh. In other words, 0000,0000,0111,1111 in binary.
  8. Seven first bits of the mask are set to HIGH. Therefore, only those bits will be compared between the two operands.
  9. The MEQ evaluates N7:3 compared to N7:5 to TRUE because of the specified mask. Note that the bits of these integers are exactly the same within the position specified by the mask.

Programming example in RSLogix 500:



The MEQ instruction is much easier to understand in binary form. Therefore, the associated tags are shown in the image above. Looking at the mask, one can easily identify which bits are labeled as “important” for comparison. Each bit set to HIGH within the mask register will be evaluated in the operands. If the bits match, the instruction will evaluate to TRUE regardless of the other bits.

In the first example, the mask is set to 0. Although this is not something you should see in the code, the instruction will be always TRUE since all bits are ignored in the comparison.

In the second example, the first seven bits are set to HIGH through a mask of 007Fh = 0000,0000,0000,0111,1111b. The bits which are set to HIGH are compared within the two operands. Since we’re dealing with two integers which have exactly the same first seven bits, the instruction evaluates to TRUE in this case as well.

Data Types Allowed for MEQ

The MEQ can be used to compare two values of identical types & uses a mask. These value can only be INTs.

  • Integer – You may specify each operand to be of “Integer” type.

Important Notes

  • Note 1 – Both operands will be evaluated within the MEQ instruction is being scanned. In an instance where the value is changed in other locations for only a brief duration, the MEQ comparison may result in unforeseen outcomes.
  • Note 2 – When working with constants, RSLogix 500 will not allow the user to use the constant in the “Operand A” field. The constant must be specified within “Operand B”. This limitation is not present in all software packages.
  • Note 3 – The user may not specify a comparison of two constants within RSLogix 500. In other words, you may not use the MEQ instruction with “Operand A” set to 7 and “Operand B” set to 20. This case will always evaluate to FALSE which should not be used.

Video Tutorial

Back to tutorials

Related Tutorials


PowerFlex 525 Parameter, Input and Output Programming Tutorial in RSLogix Studio 5000

The PowerFlex 525 series of Variable Frequency Drives from Allen Bradley is highly utilized and respected within the automation field. The drives are compact, versatile and easy to use. We’ve written an extensive tutorial on how to get started with these drives in a previous tutorial; it covers how to initialize the drive, connect it to an EtherNet/IP based PLC and how to set the right parameters. In this tutorial, we’re looking to expand on the concepts and demonstrate a way to access and utilize the multiple Input and Output options available on the drive. The reason you may want to utilize the IO is to save money on purchasing external components, integrate instrumentation into your drive and save floor space, wiring and cost. We’ve seen the need to integrate closely related sensors into a PowerFlex 525 application; this would be the right way to do it.

Vladimir Romanov

Publishing MQTT Data Using Opto 22 groov EPIC PAC

MQTT is a communication protocol that has taken off in the IIoT community. It’s a light-weight, efficient protocol that works through a publisher / broker / subscriber model. It creates an easy way for field devices to communicate and retrieve data from a single location. In this article, we’ll go over MQTT and dive into an example of how you can publish data using a groov EPIC PAC and retrieve the data using a MQTT client.

Vladimir Romanov

HMI Design - Best Practices for Effective HMI Screens

HMI Design is the practice of building HMI screens that are intuitive to the end user, pleasing to the eye and are efficient to operate. As control systems within manufacturing are migrated from traditional push button designs to primarily operated from HMI displays, HMI Design has become trivial to any new installation.Although there is a wide range of HMI based systems, the basic principles of good design remain the same. Different industries may dictate different patterns of layout for their systems, but the good practices remain.

Vladimir Romanov