Page 1 of 1
Bit Level Operations on INT32 or INT16
Posted: Sat Oct 25, 2014 1:31 am
by GTUnit
I have a INT32 tag called ControlDINT
I need to Read and Write to the individual bits in that tag.
In Compactlogix processors I can address this as
ControlDINT.0
ControlDINT.1
ControlDINT.2
ControlDINT.3 and so on up to ControlDINT.31
How can I read and write these bits using the panel?
The reference and user documentation is not of any use.
Re: Bit Level Operations on INT32 or INT16
Posted: Tue Jan 06, 2015 8:10 am
by AMitchneck
To change a single bit you can write script such as
Code: Select all
int setBit(int currentValue, int bitNumber, bool value)
{
int bit = 1 << bitNumber;
if (value)
currentValue |= bit;
else
currentValue &= ~bit;
return currentValue;
}
Note that when you write to a tag the entire tag value will be written to the controller not just the single bit you set.
Re: Bit Level Operations on INT32 or INT16
Posted: Thu Feb 05, 2015 6:32 am
by Gargy
Hello all!
'Cause I have 0 knowledge with C# and scripting I took another approach...
Each INT is a sum of numbers. Every bit has its own number. Bit 0 = 1, Bit 1 = 2... BIT 7 = 128.. And so on... If I add or subtract from INT a value of 2, then I will change only the BIT 1 in whole INT.
Example. I want to change BIT5 in the whole INT. This is decimal number 32. So I add two buttons - one is visible if BIT5 is 0 and one if BIT5 is 1. First button add 32 to the INT (Increment Analog) and the second subtract 32 (Decrement Analog). The end result is changing Bit 5 from 1 to 0 or in other direction.
I hope I helped someone...
BR
Gargy