Set a particular bit in a int16/ Circle dynamic

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
henriks
Posts: 1
Joined: Wed Mar 04, 2015 3:35 am

Set a particular bit in a int16/ Circle dynamic

Post 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.

AMitchneck
Posts: 137
Joined: Mon Jun 11, 2012 2:10 pm

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

Post 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);
Adam M.
Controls Engineer
FlexEnergy

Post Reply