getBit equivalent for use in a "Client Event Script"

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

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

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

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?

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

def getBit(i, n):
	return (i >> n) & 1
4 Likes

Thanks, this does exactly what I was looking for.