# Selection buttons integer

**URL:** <https://forum.inductiveautomation.com/t/selection-buttons-integer/38295>\
**Category:** Ignition\
**Created:** [September 2, 2020, 12:21pm UTC](https://forum.inductiveautomation.com/t/selection-buttons-integer/38295 "2020-09-02T12:21:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom.wouters](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@tom.wouters](https://forum.inductiveautomation.com/u/tom.wouters)\
**Post date:** [September 2, 2020, 12:21pm UTC](https://forum.inductiveautomation.com/t/selection-buttons-integer/38295/1 "2020-09-02T12:21:56Z")

</div>

Hello,

I have an integer tag and I would like to be able to set every bit individually with a button in that integer.  
Now for scripting I have found to use

```auto
def set_bit(value, bit):
    return value | (1<<bit)

def clear_bit(value, bit):
    return value & ~(1<<bit)
    
def getBit(value, position):
    return (value >> position) & 1
  
value = event.source.parent.DATA_Sequentie.Selectie

if	getBit(event.source.parent.DATA_Sequentie.Selectie, 0) == 0:
	value = set_bit(value,0)
	event.source.parent.DATA_Sequentie.Selectie = value
else:
	value = clear_bit(value,0)
	event.source.parent.DATA_Sequentie.Selectie = value

```

This works perfectly except I have to write te number 0 to the specific bit every time I make another button. I have to do this at the 3 different places the “0” bit is stated which could lead to forgetting this in the future. I would like this to come from one general place. Like a custom property for example where you have to write the bit number. Problem is I can’t get this to work.

Do you guys have any other suggestions on how I could set bits from an integer or how to get a custom property to work?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 2, 2020, 12:44pm UTC](https://forum.inductiveautomation.com/t/selection-buttons-integer/38295/2 "2020-09-02T12:44:09Z")

</div>

I would move your bit shift functions to a project script if they are not already there. Then create a Template to hold your button. This will allow you to create a custom property for the template to hold the bit number reference.

Then whenever you need to add a button you can just use your template and set the properties.
