Converting a decimal value to it's bit in another word clx

evilthorne

Member
Join Date
Jun 2016
Location
Kitchener Ontario
Posts
24
Well I am trying to cleanly convert a decimal value in a DINT to the corresponding bit in a different DINT So if I have the number 11 on in DINT[1] Turn the 11th bit on in the DINTbit[1] word I have to do this several times over different ranges for different applications so I am looking for a clean way rather than forcing it.

I have a range that goes from 10-20 and range that goes from 1-100. Is there an easy way to do this without just using equ and an OTE?

In my searching I have seen FAL and FSC come up a lot but every time I try to set them up I cannot get the desired result (mostly because I have never used them before).

Thank you.
 
Not sure what you mean by ranges 10-20 and 1-100, but perhaps this?


DINTbit[1+((DINT[1] AND -32)/32)].[DINT[1] AND 31]
 
If I'm understanding you (always an assumption), you have a DINT with a value, and you want to reference the bit that corresponds to that value.
E.i, if Index = 2, you want DINT.2.

If your Index were limited to 31, then it would be as simple as an indirect address of DINT.[Index].

Alas, you say your Index value can go up to 100, and there is no 100th bit in a DINT. But there is a 100th bit in an ARRAY of DInts: DIntArray[4].

Thus Index = 100 should reference DIntArray[3].4.

The formula DIntArray[(Index AND NOT 31) / 32].[Index AND 31] does just that. This can be used as a contact or a coil. But do everyone a favor and annotate the heck out of it in the rung comments so that people aren't left scratching their heads.

This assumes, that the "first" bit (when Index = 1) is the .1 bit, not the .0 bit. If not, then you'll need to modify the formula above.

You can find this in the RSLogix Help files under "Specify Bits in an Array".

HTH

Edit: You say your index is in DInt[1]. Formulas can't have arrays nested inside other arrays (i.e., DintArray[Dint[1]] ). But I believe (without testing -- caveat emptor) that if you create an alias "Index" which is defined as DInt[1], then you can have DintArray[Index], and the logic will compile.
 
Last edited:
Edit: You say your index is in DInt[1]. Formulas can't have arrays nested inside other arrays (i.e., DintArray[Dint[1]] ). But I believe (without testing -- caveat emptor) that if you create an alias "Index" which is defined as DInt[1], then you can have DintArray[Index], and the logic will compile.

Quite correct, I said this exact same thing a couple days ago on another thread.

If you ever see square brackets inside another set of square brackets, it won't compile, you cannot nest indirection, but the Alias is a back-door way, this picture says it all ...

2021-02-16_212630.jpg
 
Last edited:
Actually an array of bools is easier...man I am dumb today...need more coffee.

It depends what you want to do with that array of BOOLs.

They don't lend themselves to much in the way of "manipulation", they just are what they are, and indexable array of BOOLs.

One day you'll be writing AOIs to use DINT arrays like BOOL arrays, e.g. specify an index of 33, and it'll address DINTArray[1].1, or an index of 3187 to address DINTArray[99].19

BOOL Arrays are not "user-friendly" in so many respects....
 
Thanks guys for all the help, and I agree an array of BOOLs is not my favorite but since it is just for a set of lights on an HMI indicator and not really running anything it works well. I can make a UDT and label them for the next four times I have to do this same task.
 

Similar Topics

How can i convert negative decimal value(-100) to hexadecimal.
Replies
3
Views
7,601
I am having problems expressing an ANALOG OUTPUT 16bit INT word (0-10V Proportional Valve Voltage) as a REAL decimal number. From my...
Replies
6
Views
9,052
Do any of you Excel gurus know of a VB code or function that will convert ASCII text into it's decimal equivalent? I'm not VB savy at all. I...
Replies
3
Views
5,803
We have an AB 1395 drive controlled by a PLC-5/40 via RIO. We are developing a monitoring computer using RSView32. This computer will poll the...
Replies
12
Views
7,827
Does anyone know how to convert from a decimal number to a true binary output. For example convert the number 15 to 1111 and then be able to turn...
Replies
9
Views
14,656
Back
Top Bottom