简体   繁体   English

如何检查 PowerApps 中是否设置了位?

[英]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?如何检查 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:要查找是否设置了数字val b位,您可以使用如下表达式:

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.如果为Number设置了Bit标志(从零开始计数),则此表达式为true Otherwise false .否则为false

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

If you are going to use it often in your app, you might want to register it as a custom function for easier use如果您打算在您的应用程序中经常使用它,您可能希望将其注册为自定义函数以便于使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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