Testing if a specific bit is set in Power Automate flows

By | November 15, 2020

Bitwise operators are, likely, not the most popular operators in the low-code world, so there is no surprise Power Automate does not have those.

Which is a bit unfortunate, since, when we do need those operators, it seems like we have to opt for a custom connector/azure function/etc.

But, come to think of it, if all you need is just to see whether a certain bit is set in the integer number, it’s totally doable with Power Automate only.

Imagine you have this number (in binary form):

image

The number itself is in black, and each bit in the binary representation is “numbered” in red.

If you use “div” function to divide that number by 2, it will shift to the right and will look like this:

1110011

You can use “div” again, and you’ll get this:

111001

You can continue like this till you get the bit you were looking for in the first “bit” of the result, and, then, just use mod function to get the remainder:

mod(x, 2)

If the remainder is 1, the bit you were looking for is set. If the remainder is 0, the bit is not set.

Here is an example of how we might use this in the Power Automate flow:

image

Leave a Reply

Your email address will not be published. Required fields are marked *