Page 1 of 1

Set a particular bit in a int16/ Circle dynamic

Posted: Tue Apr 07, 2015 9:03 am
by henriks
Greetings!

I'm currently trying to make a script for setting a particual bit in an integer. The point is:

I have 16 circles(dynamics) on a row. If I "mouse enter" circle no.6 I want it to set bit number 5 in a int16. Im currently using a memory bit for each circle which is the easy set up, but may slow down the proccess (PLC <-> panel).

Its a total of 15x55 (YxX) circles/pixels for a drawing page and because of that trying to get each line of 15 circles/bits into one integer 16 memory.

Using iX T7B panel and Mitsubishi FX3U PLC.

Thanks in advance!

Henrik.

Re: Set a particular bit in a int16/ Circle dynamic

Posted: Mon Apr 13, 2015 3:47 pm
by AMitchneck
I'm assuming your integer is a tag that for this example I will call Variable.

to set a bit, use the code
Globals.Tags.Variable.Value |= 1 << numBits;
where numBits is the position of the bit (first bit = 0).

to unset a bit, use the code
Globals.Tags.Variable.Value &= ~(1 << numBits);