Interpretation of Integer Value

IvanJoseph

Member
Join Date
Aug 2015
Location
Manila
Posts
8
Hi,

Can someone help me explain in detail this integer Value.

N7[4+((N151_0 AND -16)/16)].[N151_0 AND 15]

Based on my understanding in the Program, the coil will trigger the right bit of an integer which is N7[4] in the program. Integer was used to trigger messaging for each PLC in the network (one at a time only).
 
N7 implies this was originally from a PLC/SLC program, and the N151_0 that it was translated to a Logix5000 program.

I read this logic puzzle as using the lower byte of N151_0 as the bit/coil address (i.e., "AND 15" masks the upper bytes).

The upper bytes are used as an offset into the N7 array/file to select the word whose bit is manipulated. The integer divide (i.e., "/") shifts the N7 word by 4 bits, and then a fixed offset of 4 is added to the word.

It seems like the "AND -16" is redundant, though maybe it avoids issues with the arithmetic status flags by zeroing the four bits that are shifted off the right.
 
Thanks.

It is quite Technical for me right now as I am only have started doing plc programming but your answer help a lot.
 
If you plan to spend some time in this field you should familiarize yourself with the algebraic order of operations - also sometimes referred to as 'operator precedence'. Using these rules provides a way to systematically break down a statement like the one you posted and discover what it's doing. Oh, and boolean algebra too.
 
At first glance, this looks similar to the way the we used to calculate "step bits" based on an integer.


Edit:
At second glance, it's not too far off from that. I think in your application though, you're using it to evaluate the status of bits, instead of changing.

"15" in binary is 0000 0000 0000 1111
"-16" in binary is 1111 1111 1111 0000

So, the "AND 15" only looks at the lowest 4 bits of N151_0. and the "AND -16" Looks at the rest. i.e. Bits 0-3 of N151_0 are deciding the bit, and the bits above those, are used to determine the word.

e.g.
A value of 15 in N151_0 will operate N7[4].[15]
A value of 16 in N151_0 will operate N7[5].[0]

So, for every "group" of 16, the word will increment, and for every group of 1 the bit will increment.

With a basic understanding of Logical operators (AND, OR, etc) and algebra, you should be able to write out several instances of this instruction working to help wrap your head around it.
 
Last edited:
At first glance, this looks similar to the way the we used to calculate "step bits" based on an integer.
...
So, for every "group" of 16, the word will increment, and for every group of 1 the bit will increment.

For me, this solves the mystery of why someone would write an expression like that. I would hope N151_0 is the result of previous limit checking to avoid faulting the processor with an out-of-range value.

For the OP...if you need to do a lot of binary conversions, the "Programmer" view of the Windows 7 Calculator tool can be helpful in that regard.
 
For me, this solves the mystery of why someone would write an expression like that. I would hope N151_0 is the result of previous limit checking to avoid faulting the processor with an out-of-range value.

For the OP...if you need to do a lot of binary conversions, the "Programmer" view of the Windows 7 Calculator tool can be helpful in that regard.

I would hope so as well!

Of course, if I've learned anything it's that someone somewhere has thought "Well, that should never happen" and done it without limits. :rolleyes:
 

Similar Topics

Hi as a beginner am learning about the G120 (CU240e-2pn) controlled by 1200plc 1-how can i interpret the hex values coming from the vfd...
Replies
1
Views
128
I could use some help figuring out the layout of a Remote I/O channel Diagnostic Files in a PLC5 using RSLogix5. I've attached a screen shot of...
Replies
14
Views
3,664
Inside GSD file I have something like this: Max_User_Prm_Data_Len = 3 Ext_User_Prm_Data_Const(0) = 0xC0, 0x00, 0x00 and few lines below like...
Replies
0
Views
2,024
Hi all, I've got an SEW device I'm trying to set up to talk to a ControlLogix. I've used this exact combination before and everything has worked...
Replies
4
Views
2,343
Hi all, I am doing a project for GM and in the specifications it states: Logic shall be developed in SFC fashion and written in ladder logic...
Replies
20
Views
6,724
Back
Top Bottom