Finding MSB in an array

CoderByNature

Member
Join Date
Jun 2023
Location
Canada
Posts
5
Hey all, pretty new to PLC and got a question regarding finding the MSB or the last non-zero bit in a SINT array in studio5000...

I am reading an RFID tag in a SINT array and then copying that data into my RFID.Data string. I was wondering if there was a way to find the length of that data in the SINT array so I can use that as my RFID.Len so that the length of the string is only as long as the data I am reading.

Also wondering if it would be easier to leave the length of the string long on purpose and then just truncate any '$00' values, i also do not know how to do that.
 
Last edited:
FSC?

Or binary search:

MSB

Invariant: sintval < 128; sintval.[hi] bit value is 0; hi starts as 7 and hi > msb.

  1. LES sintval 0 MOV 7 msb => exit
  2. MOV mid 16 mid MOV msb 4
  3. BST GEQ sintval mid MUL mid 4 midtmp ADD msb 2 msb NXB LES sintval mid DIV mid 4 midtmp SUB msb 2 msb BND MOV midtmp mid
  4. BST GEQ sintval mid MUL mid 2 midtmp ADD msb 1 msb NXB LES sintval mid DIV mid 2 midtmp SUB msb 1 msb BND MOV midtmp mid
  5. LES sintval mid SUB msb 1 msb
LENGTH of null-terminated string in SINT

N.B. assumes entire string is all elements in SINT array from sintarray[0] to up to last element before first $00, and all elements after first $00 are also $00

Invariant: sintarray[hi] is $00

  1. MOV 0 lo MOV L hi MOV L mid ;;; L is length of SINT array
  2. OTR mid.0 DIV mid 2 mid ADD lo mid mid
  3. NEQ sintarray[mid] 0 MOV mid lo
  4. EQU sintarray[mid] 0 MOV mid hi
  5. SUB hi lo mid
  6. GRT mid 1 JMP 2.
  7. MOV hi RFID.Len
I think those two algorithms are correct, but it is rare to get right on the first try (cf. here), so they might just be close.
 
Last edited:
Thank you for the help! I looked into FSC and it does what I was need it to do. Do you happen to know anything about shifting strings up or down an array?
 

Similar Topics

Hello All. I have a question for the group. I am working on a vision system where parts are fed onto a turntable and pass under a camera where it...
Replies
19
Views
4,652
Hi all, I'm in the process of upgrading a PanelView1200 HMI program to be developed in FactroyTalk View Studio. The filetype for PanelView 1200...
Replies
7
Views
281
Having an issue connecting to my Micro820 PLC. I don't have an IP Explorer and I know its MAC Address is 5C:88:16:D8:E6:65. I'm connected to the...
Replies
5
Views
918
I have reached a dead end trying to find an EDS file. Manufacturer says to contact third party tech support. Clueless. RSLINX can see it, just...
Replies
9
Views
1,792
Hello, I have an array of 300 of UDT. In each UDT is an array of 3 DINT and another array of 3 REAL. I have 10 controllers that pull data from...
Replies
7
Views
1,160
Back
Top Bottom