toBinary fails to resolve in script

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.

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

What makes you think that function even exists?

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

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.

>>> from java.lang import Integer
>>> Integer.toBinaryString(255)
u'11111111'
1 Like

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.

1 Like