# getBit equivalent for use in a "Client Event Script"

**URL:** <https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [October 2, 2017, 5:54pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538 "2017-10-02T17:54:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [October 2, 2017, 5:54pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538/1 "2017-10-02T17:54:20Z")

</div>

I am writing a script in the “Client Event Scripts” section would like the ability to get a single bit from an integer tag; the same result if I was to use the _**getBit()**_ function in an expression. _**getBit(**)_ does not seem to work. Has anyone run into this before and have a suggestion for an alternative?

**_getBit()_** documentation: [https://docs.inductiveautomation.com/display/DOC79/getBit](https://docs.inductiveautomation.com/display/DOC79/getBit)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 2, 2017, 5:58pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538/2 "2017-10-02T17:58:27Z")

</div>

No expression functions can be use in python. Use python operators. Something like:

```auto
myBit13 = bool(system.tag.read('path/to.myInteger').value & 0x2000)

```

---

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [October 2, 2017, 7:25pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538/3 "2017-10-02T19:25:49Z")

</div>

Thanks! I have been playing around with this but have been unable to figure it out.

Lets say **Value = 8** ; in binary that’s: **1000**. Using the **getBit()** function this is what is returned.

bit1 =\> getBit(Value, 0) = 0  
bit2 =\> getBit(Value, 1) = 0  
bit3 =\> getBit(Value, 2) = 0  
bit4 =\> getBit(Value, 3) = 1

How can I return the same thing using the python **bool()** function?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 2, 2017, 7:32pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538/4 "2017-10-02T19:32:42Z")

</div>

Maybe just define your own `getBit` function? It’s just bit shifting:

```python
def getBit(i, n):
	return (i >> n) & 1

```

---

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [October 2, 2017, 7:36pm UTC](https://forum.inductiveautomation.com/t/getbit-equivalent-for-use-in-a-client-event-script/15538/5 "2017-10-02T19:36:57Z")

</div>

Thanks, this does exactly what I was looking for.
