# Reading Bits from Integer Tag

**URL:** <https://forum.inductiveautomation.com/t/reading-bits-from-integer-tag/17972>\
**Category:** Ignition\
**Created:** [May 9, 2018, 1:32pm UTC](https://forum.inductiveautomation.com/t/reading-bits-from-integer-tag/17972 "2018-05-09T13:32:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpeasley](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mpeasley](https://forum.inductiveautomation.com/u/mpeasley)\
**Post date:** [May 9, 2018, 1:32pm UTC](https://forum.inductiveautomation.com/t/reading-bits-from-integer-tag/17972/1 "2018-05-09T13:32:41Z")

</div>

Is it possible to read the bit of an OPC Tag set as an integer?

I want to read an individual bit off a DINT tag pulled from a PLC in scripting, without having to break the tags into individual Igniton tags.

---

<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:** [May 9, 2018, 1:55pm UTC](https://forum.inductiveautomation.com/t/reading-bits-from-integer-tag/17972/2 "2018-05-09T13:55:51Z")

</div>

There 's an expression function [getBit](https://docs.inductiveautomation.com/display/DOC79/getBit)…  
If you want in scripting, look [here](https://wiki.python.org/moin/BitManipulation)…

```auto
def getbit(x,n):
  "Get the n-th bit of the number x"
  return x & (1 << n) and 1 or 0

```

Explanation: x & (1 \<\< n) means bitwise AND between x and 2^n. And the expression P and 1 or 0 means: if P then return 1, otherwise return 0.

And this works for numbers of any size. Python is not limiting you to 32 bit integers.
