# toBinary fails to resolve in script

**URL:** <https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision\
**Created:** [April 21, 2025, 3:16pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331 "2025-04-21T15:16:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicole\_McCormack](https://avatars.discourse-cdn.com/v4/letter/n/b77776/32.png) [@Nicole\_McCormack](https://forum.inductiveautomation.com/u/Nicole_McCormack)\
**Post date:** [April 21, 2025, 3:16pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331/1 "2025-04-21T15:16:11Z")

</div>

My code keeps erroring so I tried to just submit the example from the manual and that also errors.  
In script console just to test. This is the same error in my script as well so not clear when this broke because I believe it worked when I first put it in.

```python
res=toBinary(255)

```

````python
>>> 
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'toBinary' is not defined
>>> ```
````

---

<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:** [April 21, 2025, 3:18pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331/2 "2025-04-21T15:18:10Z")

</div>

~~What makes you think that function even exists?~~

Ah, this is an **expression** function, not a scripting function.

---

<div class="post-metadata">

**Author:** ![Nicole\_McCormack](https://avatars.discourse-cdn.com/v4/letter/n/b77776/32.png) [@Nicole\_McCormack](https://forum.inductiveautomation.com/u/Nicole_McCormack)\
**Post date:** [April 21, 2025, 3:22pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331/3 "2025-04-21T15:22:27Z")

</div>

Ah, missed that bit in the manual. Is there an easy equivalent in scripting? I am reading back the error from a torque tool in a client tag change script and wanting to parse that data as binary. Not sure how to engage and expression at that time.

---

<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:** [April 21, 2025, 3:26pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331/4 "2025-04-21T15:26:24Z")

</div>

```python
>>> from java.lang import Integer
>>> Integer.toBinaryString(255)
u'11111111'

```

---

<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:** [April 21, 2025, 3:35pm UTC](https://forum.inductiveautomation.com/t/tobinary-fails-to-resolve-in-script/105331/5 "2025-04-21T15:35:07Z")

</div>

If you want specific bits as booleans, you might want to use a custom properties and expression bindings with the `getBit()` expression function. (Or use bitwise And in your script to isolate the bit(s) of interest.) Stringifying is not very efficient, unless you intend to actually display the binary format.
