# Bit in double integer

**URL:** <https://forum.inductiveautomation.com/t/bit-in-double-integer/34079>\
**Category:** Ignition\
**Created:** [April 21, 2020, 3:49pm UTC](https://forum.inductiveautomation.com/t/bit-in-double-integer/34079 "2020-04-21T15:49:45Z")\
**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:** [April 21, 2020, 3:49pm UTC](https://forum.inductiveautomation.com/t/bit-in-double-integer/34079/1 "2020-04-21T15:49:45Z")

</div>

Dear experts,

I have a window where i added a custom property to link to a data type.  
This data type consists of one “CMD” which is a doubleinteger DI0 to be precise.

Now this window will be my main sequence example and I’m trying to add a button that will set a bit in this double integer tag.

I’ve done some research and I have found a few examples but they won’t work for me. Do any of you see what I’m doing wrong in my scripting?

```auto
def setBit(value, position, newValue):
   newValue = (newValue & 1) << position
   mask = 1 << position
   return (value & ~mask) | newValue   

system.tag.write(setBit("event.source.parent.DATA_Sequentie.CMD",0,1))

```

Thanks in advance this will help me a lot!

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [April 21, 2020, 4:14pm UTC](https://forum.inductiveautomation.com/t/bit-in-double-integer/34079/2 "2020-04-21T16:14:40Z")

</div>

These work for integers of any size, even greater than 32 bit:

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

def clear_bit(value, bit):
    return value & ~(1<<bit)

value = event.source.parent.DATA_Sequentie.CMD
value = set_bit(value,1)
event.source.parent.DATA_Sequentie.CMD = value

#or

event.source.parent.DATA_Sequentie.CMD = set_bit(event.source.parent.DATA_Sequentie.CMD,1)

```

In the linked custom property you must check Bidirectional…

I found this [here](https://stackoverflow.com/questions/12173774/how-to-modify-bits-in-an-integer)…😉
