简体   繁体   中英

How to check if a bit is set in PowerApps?

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.

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:

在此处输入图片说明

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 .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM