# Coverting word to bit status

**URL:** <https://forums.losant.com/t/coverting-word-to-bit-status/1231>\
**Category:** Feature Request\
**Tags:** workflow, binary-parsing\
**Created:** [November 8, 2018, 5:00pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231 "2018-11-08T17:00:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [November 8, 2018, 5:00pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/1 "2018-11-08T17:00:03Z")

</div>

What do you suggest I use in a workflow too convert a word to bit values?  
For example 8 would be 0000 1000, and 12 would be 0000 1100, and so on?

Each bit would mean different alarms going on /off.

This is a common way to relay alarm information from PLC’s.

---

<div class="post-metadata">

**Author:** ![Michael\_Kuehl](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/michael_kuehl/32/99_2.png) [@Michael\_Kuehl](https://forums.losant.com/u/Michael_Kuehl)\
**Post date:** [November 8, 2018, 5:23pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/2 "2018-11-08T17:23:43Z")

</div>

At the moment, I think you would need to use a [Function](https://docs.losant.com/workflows/logic/function/) node, and write custom javascript to extract those values (take a look at [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise\_Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators)). But you are right, this is not an uncommon thing to need to do, and we should add some features around this into the workflow engine!

---

<div class="post-metadata">

**Author:** ![Tim\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@Tim\_Hoffman](https://forums.losant.com/u/Tim_Hoffman)\
**Post date:** [November 9, 2018, 12:01am UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/3 "2018-11-09T00:01:13Z")

</div>

We do this a lot.

I usually have a data table with the bits defined along with the messages. For instance converting NFPA codes on a genset.

So I use the following to unpick the bits,

```javascript
    payload.data.nfpa = []

    function intToUint(int, nbit) {
        var u = new Uint32Array(1);
        nbit = +nbit || 32;
        if (nbit > 32) throw new RangeError('intToUint only supports ints up to 32 bits');
        u[0] = int;
        if (nbit < 32) { // don't accidentally sign again
            int = Math.pow(2, nbit) - 1;
            return u[0] & int;
        } else {
            return u[0];
        }
    }

    payload.data.state_bits = intToUint(payload.data.running_state,16).toString(2).split("").reverse().join("");

```

Then will loop of state\_bits using each item in the loop as the key for the item in the datatable.

A simple node to at least unpick the bits would be good.

I can build this in a custom node, but would prefer to run this on the agent, and custom nodes aren’t supported on agents. yet.

T

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [November 20, 2018, 8:12pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/4 "2018-11-20T20:12:22Z")

</div>

I don’t need it on the agent this time, so a custom node would work.

---

<div class="post-metadata">

**Author:** ![Lars\_Andersson](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lars\_Andersson](https://forums.losant.com/u/Lars_Andersson)\
**Post date:** [April 10, 2019, 2:39pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/5 "2019-04-10T14:39:16Z")

</div>

Any features around this yet?

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [April 10, 2019, 3:04pm UTC](https://forums.losant.com/t/coverting-word-to-bit-status/1231/6 "2019-04-10T15:04:53Z")

</div>

Hey @Lars_Andersson,

Nothing yet. But, we just enabled voting on the feature request here in the forums. You should give this a vote!
