# Status Word Tag to Single State Integer

**URL:** <https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995>\
**Category:** Ignition\
**Created:** [August 20, 2025, 4:10pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995 "2025-08-20T16:10:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [August 20, 2025, 4:10pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995/1 "2025-08-20T16:10:40Z")

</div>

I got some integer tags which bits represents distinct states. I require to convert to an integer tag that represents its state.

Any idea how to best implement this?

My initial approach is to use expression tag, and enable history. I am afraid though this will induce runtime log?

Second approach is to implement on gateway script, and do a write query to database for history?

What do you guys think?

---

<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:** [August 20, 2025, 4:15pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995/2 "2025-08-20T16:15:46Z")

</div>

Expression tag if you need history. Expression in the UI otherwise.

Consider using the `binEnum()` function if the bits turn on only one at a time.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [August 20, 2025, 4:27pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995/3 "2025-08-20T16:27:37Z")

</div>

Ain’t Expression fall same issue with tag value change event limitation? ["Tag Change" gateway event script vs "Value Changed" tag value event](https://forum.inductiveautomation.com/t/tag-change-gateway-event-script-vs-value-changed-tag-value-event/105407)

---

<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:** [August 20, 2025, 4:42pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995/4 "2025-08-20T16:42:04Z")

</div>

Expression tags have different execution pool from tag event scripts. And expressions are much more efficient than jython. (Don't use `runScript()` in your expressions to minimize chances of trouble.)

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 25, 2025, 8:39pm UTC](https://forum.inductiveautomation.com/t/status-word-tag-to-single-state-integer/109995/5 "2025-09-25T20:39:33Z")

</div>

Hope I am not bothering.

What is the random integer range I need to generate, to hit the first (least significant) 16 bit of integer tag.

Background:  
16 bit from PLC is stored as Integer (Tag) in Ignition.  
I want to exercise, write random integer value to bit change the least 16 bit of Integer type.

Edit:  
I got a quick answer from AI

```python
random_16bit = random.randint(0, 65535)
print(random_16bit)

```

or

```python
random_16bit = random.randint(-32768, 32767)
print(random_16bit)

```

shoot I got this.
