Splitting a word into integers

a dummy way to do this is create an AOI with 10 boolean input, and 1 int output:

in the AOI,
1) convert all 10 bool input to int using mov function (bool to int)
2) after conversion, bit 0 mul by 1, bit 1 mul by 2, bit 2 mul by 4......bit 9 mul by 512
3) sum all the result together and pass to int output

you can then map your bit 0-1, or bit 3-12 on the AOI, example if the AOI input bit0 and 1 both on, 1x1 + 1x2 you will get int value of 3, lets say if AOI all input is on, you will get 1x1 + 1x2 + 1x4 +......1x512 = 1024

Hope this help
 
There are no AOIs in a 1400, but you could shoehorn in something similar to one and make it nice and ugly and confusing.

I would do the brute force method JaxGTO described, but I am a brute force kind of guy. No need to get cute just for sake of "elegance".

Just use a BFH, and nail the bits where you want them, one by one with much greater efficiency that anything with a loop.
 
I would do the brute force method JaxGTO described, but I am a brute force kind of guy. No need to get cute just for sake of "elegance".

Even that loop approach was fuglier than I'd hoped for, and on top of that in a 1400 each "caller" would need to move things in and out of the N255 file "arguments," etc.


So yah, I agree, no point trying to put lipstick on the pig.


That said, for bit ranges that don't touch the sign bit e.g. ten bits 3-12:
AND srcint 8184 dstint
DIV dstint 8 dstint
Cleaner than brute force XIC/OTE; possibly faster per scan but not enough to matter (lose ~1.5μs on instructions; gain maybe 4-8μs for fewer rungs).
 
Here is a simple one, just and & shift.
Note: the way this works with the shift is it works on the same variable so the AND function for the bits 3-12 the result is shown as the result of the shift it's just the way it works, rather than shift & store it into another variable it works on the source variable.
Rung 1 just masks bits 0-1
Rung 2 masks the bits 3-12
Rung 3 shifts the 3-12 to 0-9

Masked move equv.png
 

Similar Topics

Any one know how to take a floating point number and convert it so that it can be split to span 2 16-bit words in the +/- 0x7fffffff hex format...
Replies
18
Views
5,239
I am close to wits end and would appreciate any new perspective. Cannot go into minutia, but here is a rough rundown of the system and issue we...
Replies
26
Views
9,199
Would it be wise / safe to split a 24vdc input from a switch to a PLC and relay? I currently have 14 of the same type of equipment that each have...
Replies
2
Views
1,515
Any one know of way to split a 4-20 mA signal 4 ways? Do they even make such a device? Thanks
Replies
12
Views
3,610
I have an application where I need a single SSI encoder to connect to both a safety controller (SICK Flexi Soft) and a general-purpose PLC...
Replies
3
Views
2,061
Back
Top Bottom