Extract bit from integer

Hi.

I use Grafana 8.0.5 for the visualisation of data from hardware equipment. I receive a status word (integer value) which every bit is the status of a specific error.

I want to extract every bit and map values but I can’t understand how to convert integer to an array of bits or something else.

Thanks

What is your data source? Can you show an example of the integer you wish to extract bits from?

Hi,

Same problem here:

  • Data source is Prometheus
  • Example value is 81 (0b0101 0001). Each bit represents a different status (e.g. pump is running).

I wonder if it is possible to extract a certain bit from my example value.

Best greetings
Sebastian

Hi Sebastian,

I haven’t experience with Prometheus but I solved my problem in another way, with database functions. I use TimescaleDB (PostgeSQL). I hope it will be helpful for someone.

SELECT
  "time" AS "time",
  (((((tagvalue)::int)::bit(32)>>0)&'00000000000000000000000000000001')::int) AS "Fault1",
  (((((tagvalue)::int)::bit(32)>>1)&'00000000000000000000000000000001')::int) AS "Fault2",
  (((((tagvalue)::int)::bit(32)>>2)&'00000000000000000000000000000001')::int) AS "Fault3",
FROM realtimetable
WHERE
  $__timeFilter("time") AND
  tagname = 'Device1'
ORDER BY 1