Dataset with a Interger to lookup bit location

I created a Internal Custom property of a Dataset inside a template. Inside the dataset column 1 contains the values 0-31. Column 2 has a string value - Running, Stopped, Paused…etc… I want to do a lookup in the dataset from an Integer in the PLC, but 0 would equal bit 0 and bit 31 would equal value 31 in the dataset. Each Bit in the PLC represents a different status.

Is there an easy way to do this - I was looking at the Logic/lookup function would work - but would need to do a lookup on the bit location. As multiple status bits could be true and it would only show the first bit on.

Thanks for any help on this one.

Add this script to your project or Global script library.
This code will return the first bit that is true.

def lowestSet(tagpath):
	import system
	int_type = system.tag.getTagValue(tagpath)
	
	low = (int_type & -int_type)
	lowBit = -1
	while (low):
		low >>= 1
		lowBit += 1
	return(lowBit)		

Now I used a Label and added the following code to the Text binding:
I created a dataset called Status on the Root Container.

try(
{Root Container.Status}[
toInt(
runScript("shared.Functions.lowestSet('Test_CLX/Chris')",1000)),1],
"Error")

If the tag value is zero, it will error with ArrayIndexOutOfBounds, so I wrapped it in a try.

Hope that helps.

Cheers,
Chris