3

How do I check if a particular bit is set on an integer value within a PowerApp? There doesn’t seem to be a built-in operator or function for bit manipulation.

As I do need this for quite few operations, using an external / Custom Connector is probably too expensive for me.

muffel
  • 7,004
  • 8
  • 57
  • 98

2 Answers2

2

To find if a bit b of a number val is set, you can use an expression like the one below:

RoundDown(Mod(val,Power(2,b+1))/Power(2,b),0)

An example of this expression is shown below:

enter image description here

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
2

Formula

Mod(Trunc(Number / (2 ^ Bit)), 2) = 1

This expression will be true if Bit flag (counting from zero) for the value Number is set. Otherwise false.

Examples

32 (00100000)

Number = 32 Bit = 0 : false
Number = 32 Bit = 4 : false
Number = 32 Bit = 5 : true

33 (00100001)

Number = 33 Bit = 0 : true
Number = 33 Bit = 4 : false
Number = 33 Bit = 5 : true

Reusability

If you are going to use it often in your app, you might want to register it as a custom function for easier use

J-M
  • 1,207
  • 11
  • 18