Decimal to bit conversion

Hello.
First of all hello to the community.

I’m getting from a PLC a 32bit decimal entry, for more details 2013265974. That is stored in influx. I need to get different bit’s to know if an alarm is enabled or no.
Decimal to binary logic is explained in this webpage:

https://www.rapidtables.com/convert/number/decimal-to-binary.html?x=2013265974

So, I need the bit 8 to show in grafana is that item is enabled or not., does it exist any way to convert that in flux?

Thank you

In 2,0 there doesn’t appear to be any bitwise operators in the flux language.

In the older sql-style query language there is something you might be able to use:

This older query language is still available via the rest interface too in 2.0

If you get it working, we’d greatly appreciate it if you posted a reply here on this thread outlining in brief what the raw data looks like, and what your final queries ended up as.

I was also interested in the question and I also did not find any bitwise operators in the documentation…
I cannot believe it… :unamused:

I could think of a few workarounds. :wink:

You could convert the integer input into bytes with the bytes() function.
Bit 8 is the first bit of the second byte.
So you could treat the second byte with modulo % 2.
If the result is 1, bit 8 is set.
If the result is 0, bit 8 is not set.

It’s rather complicated, but you should be able to do it roughly.

1 Like

I immediately created an issue on Github about this :wink: