Using AND in a Pointer for array

Hello all,

Recently I came across a very interesting block of logic that used an AND instruction in a pointer to dynamically reference different bits in an array of Integers.
It accomplished this by comparing a DINT to a static value (not a tag).
EX: Array[(Pointer AND 8)]

I was just wondering if anyone else has come across something similar and knows how to do it?
I have tried replicating it with another array in a different program with no success.

Any advice would be great!

Thank you,
 
Well, kinda neat idea... another way to avoid out of bounds without a LIM, actually somewhat more bulletproof since a pointer could possibly be written from an external source in the fraction of a mS between LIM and reference. Played around a bit offline with V20 and V34. Didn't have a problem verifying array element or bit level with or without parentheses. I even tried one pointer of a 2D array.

Made me think of a crash & burn I haven't tried. Now I want to reference bit.32 of a DINT.
 
Recently I came across a very interesting block of logic that used an AND instruction in a pointer to dynamically reference different bits in an array of Integers.
It accomplished this by comparing a DINT to a static value (not a tag).
EX: Array[(Pointer AND 8)]

I was just wondering if anyone else has come across something similar and knows how to do it?

The only place I have seen that is in code translated from RSLogix 500 to RSLogix/Studio 5000.

The mask would be -16 (for an array of 16-bit integers) in a 5000-based array to model a 500-based bit-in-file reference like this N7:0/[bit_offset]; note that the value of bit_offset can be anywhere from 0 to 4095, to access any of the bits in Data File N7 from N7:0 though N7:255.

In 5000, there would be a 16-bit integer array tag N7 with up to 256 elements (e.g. N7[0..255]), and the reference to the bit at offset bit_offset from bit N7:0/0 would be, in 5000:
  • N7[(bit_offset AND -16) / 16].[bit_offset AND 15)]
where
  • the expression (bit_offset AND -16) / 16 is the offset, into the integer array, of the integer element that contains that bit, and
  • the expression bit_offset AND 15 is the offset of the bit in that integer element
 

Similar Topics

Hi all....... someone knows if is possible in S7, using the indirect adressing by means of a pointer L P## to read a data struct defined as...
5
Replies
4,519
Views
We have a repair hole that carriers come into. As they come in they pass a RFID reader and each carrier has a tag. The repair hole can hold 5...
2
Replies
2,619
Views
Hello Folks! I'm still trying to get the hang of using STL and Pointers in Step 7 (V5.5). For background, I'm writing a sample application...
7
Replies
4,266
Views
Hey all, Having a little trouble figuring out a clean way to do this. What I'm trying to do is copy a serial number that is read from an RFID tag...
11
Replies
5,352
Views
Hey everybody, I've been trying to write a function in STL that takes an indexnumber and a UDT type to calculate a pointer to specific UDT in a...
12
Replies
4,630
Views
Top