# Dataset with a Interger to lookup bit location

**URL:** <https://forum.inductiveautomation.com/t/dataset-with-a-interger-to-lookup-bit-location/9540>\
**Category:** Ignition\
**Created:** [January 13, 2015, 2:35pm UTC](https://forum.inductiveautomation.com/t/dataset-with-a-interger-to-lookup-bit-location/9540 "2015-01-13T14:35:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSI600](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@DSI600](https://forum.inductiveautomation.com/u/DSI600)\
**Post date:** [January 13, 2015, 2:35pm UTC](https://forum.inductiveautomation.com/t/dataset-with-a-interger-to-lookup-bit-location/9540/1 "2015-01-13T14:35:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CPowell](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@CPowell](https://forum.inductiveautomation.com/u/CPowell)\
**Post date:** [January 14, 2015, 10:04pm UTC](https://forum.inductiveautomation.com/t/dataset-with-a-interger-to-lookup-bit-location/9540/2 "2015-01-14T22:04:24Z")

</div>

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

```auto
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.

```auto
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
